Home > Software design >  find python run script though PID
find python run script though PID

Time:03-07

I know the PID in which somebody uses python to run a script. This process is created by a public user account using the system's own python. I want to find out what program is running. Can I get the absolute location of the script based on this PID?

Many thanks.

FIY OS: Ubuntu 18.04

CodePudding user response:

Quoting from: https://askubuntu.com/questions/1392113/how-can-i-check-which-python-script-is-being-run-given-its-pid

You can try reading the file named cmdline in the directory /proc//. It is a null-joined list of the program and its arguments. Here is an example on my ubuntu for the process handling unattended-upgrades:

$ cat /proc/133319/cmdline | xargs -0 echo
/usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal

If you want to obtain the result from within another python script, you may use the subprocess module to execute the necessary terminal command.

  • Related