Othman Benchekroun
Othman Benchekroun

Reputation: 2018

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

Upvotes: 2

Views: 2214

Answers (1)

Anand Tzu
Anand Tzu

Reputation: 66

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

Upvotes: 5

Related Questions