Closed
Description
psutil cache the process name based on (pid, creation_time), but in case of exec it could change.
I can reproduce this issue with:
- start bash in one terminal. Use "echo $$" to find PID of this shell (e.g. 1626)
- Run a psutil.process_iter() loop => process.name() return "bash" when I'm on pid == 1626
- run "exec sh" on the bash terminal
- Re-run the same psutil.process_iter() loop, process.name() is still "bash"
The loop used is :
for p in psutil.process_iter():
if p.pid == 1626:
print(p.name(), p.cmdline())
Note: the cmdline() - which is not cached - show the new name.
A way to request name without using cache may be valuable.