12

Using the command 'top' I can see 2 python scripts are running. However, how do I check their names or directory/location? I want to identify them so I can see what is running properly and what isn't.

  • 1
    lsof -p $PID would be a good start. $PID can also be a comma-delimited list of PIDs. Also, tons of data will be exposed in /proc/$PID/. – DopeGhoti Jan 24 '14 at 4:43
18

You can get a list of python processes using pgrep:

pgrep -lf python

This, however, does not list the whole command line. If you have a recent version of pgrep you can use -a to do this:

pgrep -af python

Otherwise, you can use /proc:

IFS=" " read -ra pids < <(pgrep -f python)
for pid in "${pids[@]}"; do
    printf '%d: ' "$pid"
    tr '\0' ' ' < "/proc/$pid/cmdline"
    echo
done
3

I usually use ps -fA | grep python to see what processes are running.

This will give you results like the following:

UID     PID   PPID  C STIME TTY      TIME     BIN            CMD
user    3985  3960  0 19:46 pts/4    00:00:07 path/to/python python foo.py

The CMD will show you what python scripts you have running, although it won't give you the directory of the script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.