Skip to content
Advertisement

How to list all concurrent python processes in my CLI?

I have opened several terminals in parallel:

my_name console  Jul  5 17:00  old         191
my_name ttys002  Jul  9 22:07   .        22109
my_name ttys004  Jul 10 07:17 00:04      23432
my_name ttys006  Jul  9 18:52 00:09      20880
my_name ttys007  Jul  9 18:53 00:09      20913

And in two of those terminals, I have launched a python file, which includes iterations, to keep the process running.
And I would like to have the list of all python processes running.
When I type:
$ ps -ef | grep python or $ps -elf | grep python
I only get the current terminal:

501  4342  3974   0 Mer08   ??         8:59.94 /Users/my_name/.vscode/extensions/ms-python.python 2021.6.944021595/languageServer.0.5.59/Microsoft.Python.LanguageServer
501 23945 22110   0  7:26   ttys002    0:00.01 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox python

How could I get a full list of the terminals with the associated python processes ? My end goal is to terminate python processes using python os.subprocess and other libraries.

Advertisement

Answer

To view all current processes execute

ps -ax

-a flag stands for all processes -x will display all processes even those not associated with the current tty

refer here

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement