Skip to content
Advertisement

Get source file path of a running python script from process id

I have a process running in the background, a python one, with ps -ef I can see filename from running command : UID PID PPID ... python ./filename.py

How can I know where the file is located

Advertisement

Answer

pwdx < PID > gives full directory the process is running from.

So, the full script would be

ps -ef | grep 'your process' | awk '{print $2}' | xargs pwdx

Though, you can simplify this into

pgrep 'your process' | awk '{print $1}' | xargs pwdx
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement