Skip to content

Process.name() cache may be outdated #692

Closed
@PierreF

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.

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions