Open Jongy opened 1 year ago
I think it would be an improvement, but how do we know if we're referring to the right version of the exe file?
Let's assume I start ./helloworld
as pid1, and N minutes later ./helloworld
as pid2.
Process(pid1).exe()
will report the original exe path for pid1 and pid2; in procfs, /proc/pid1/exe
will read ./helloworld (deleted)
for pid1. ./hellworld
on disk, but pid2 is a fork of pid1?
Process(...).exe()
will report original path for pid1 and pid2, but in procfs we will see ./helloworld (deleted)
for both pids; our caching won't be able to tell they both refer to the same exe, and will report incorrect version for pid2, right?I think we need to look up modification time for exe file matching (not younger than) the create_time of the process. This should help with first bullet above, but not with forked processes.
The function accepts a
psutil.Process
and reads its /proc/pid/exe. It is cached on a per-Process basis, but Processes replace often and we can do smarter caching based on modification time of the absolute path of/proc/pid/exe
based on the mnt ancestor, so/proc/{get_mnt_ns_ancestor(process)}/root/path/to/exe
.