Federico Ponzi
Federico Ponzi

Reputation: 2775

Find path of python program in execution

In my terminal, I can see a python program in execution:

python3 app.py

where can I find app.py?

I've tried to look in the /proc/$pid/exe but links to the python interpreter.

I have many app.py programs in my system, I want to find out exactly which is in execution with that pid.

Upvotes: 1

Views: 1189

Answers (3)

Pitto
Pitto

Reputation: 8579

If you are on Mac Os X please try using:

sudo find / -type f -fstype local -iname "app.py"

If you are not on Mac Os X you can use:

sudo find / -mount -type f -iname "app.py"

The find command will start from your root folder and search recursively for all the files called "app.py" (case insensitive).

Upvotes: 0

hiro protagonist
hiro protagonist

Reputation: 46849

i ran a short test on my machine and came up with this... maybe it helps:

  1. find the process id PID of the job in question:

    $ ps -u $USER -o pid,cmd | grep app.py

    the PID will be in the first column. assign this number to the variable PID.

  2. find the current working directory of that job:

    $ ls -l /proc/$PID/cwd

    (for more info: cat $ cat /proc/$PID/environ)

your app.py file will be in this directory.

Upvotes: 3

nandal
nandal

Reputation: 2634

check the file

/proc/[PID]/environ

There is PWD variable contains full path of the directory containing the executable file.

Upvotes: 2

Related Questions