75

How to display list of running processes Python with full name and active status?

I tried this command: pgrep -lf python

1

6 Answers 6

152

Try this command:

ps -ef | grep python

ps stands for process status

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

4 Comments

Thank you, one comment, how to display full path to running file(process)?
how is this different from ps -aux | grep python?
@CharlieParker Please look at the ps man page to see the difference, more specifically at the examples secion here: man7.org/linux/man-pages/man1/ps.1.html#EXAMPLES
ps -ef | grep [p]ython
19

ps -aux will give all process grep python

ps -aux | grep python

2 Comments

You don't need a dash before aux, just ps aux.
how is this different from ps -ef | grep python?
14

You could also setup a "watch" in a separate window to constantly monitor Python processes as you run a script: watch -n 1 "ps u -C python3". Particularly useful when developing with multiprocessing.

Comments

3

View 1 shows me all threads of python running, I use this for checking for memory leaks:

View 1

ps -ef | grep [P]ython


#  502 14537 14484   0  5:47PM ttys000    0:00.58 /Library/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python
#  502 14940 14484   0  5:57PM ttys000    0:00.55 /Library/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python

View 2

ps -ef | grep python


#  502 14950 14484   0  5:58PM ttys000    0:00.00 grep python

View 3

ps aux | grep python


# jayrizzo         14957   0.0  0.0 34132060    896 s000  S+    5:58PM   0:00.00 grep python

All 3 variations provide slightly different results.

Comments

0

Try this command

ps -ef | grep python

ps stands for process status

Comments

0

If you have the psutil module available, you can iterate over the processes you have permission to read, and select the processes executing the same binary:

import psutil

this_proc = psutil.Process()
for p in psutil.process_iter(['pid', 'exe', 'cmdline']):
    if p.info['exe'] == this_proc.exe() and p.info['pid'] != this_proc.pid:
        print(p.info['pid'], ' '.join(p.info['cmdline']))

This works even if the process has changed its command line entry while running.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.