1

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.

8
  • where is your app.py file ? go there and run python3 app.py Commented May 23, 2018 at 13:46
  • @zimdero this is my actual question. How can I find this app.py file? Commented May 23, 2018 at 13:46
  • 3
    find / -type f -name "app.py" Commented May 23, 2018 at 13:47
  • Thanks @0x00, I've also tried updatedb and locate app.py but I've several of them. Commented May 23, 2018 at 13:48
  • Isn't it in the current directory of that shell process? Commented May 23, 2018 at 13:48

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I think (but didn't check) that environ will contain PWD as it was when the process was launched, whereas cwd would reflect the current working directory, which can change if the script executes chdir.
Hello there! Environ hadn't the PWD variable in it, and had apparently no helpful informations. I've found out that the program was in a docker contianer, by check the CWD file, that stated that the cwd was /app that obviously, wasn't in my root. Thanks a lot!
2

check the file

/proc/[PID]/environ

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

2 Comments

Thanks, but apparently there is no PWD directory in there.
it's variable in /proc/[PID]/environ file
0

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).

3 Comments

I do not recommend doing this. Although this solution might look simpler, it will scan your entire filesystem. And if you have mounted some remote shares, running this command will take extra long time to complete, stressing your hard drive, network, and your patience.
Your update is wrong. local is not a valid file system type.
Correct, it is only valid on Mac. Added also GNU find details. @AndrejsCainikovs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.