D
D
DVoropaev2019-08-13 07:21:31
linux
DVoropaev, 2019-08-13 07:21:31

How to check if a process with that name is running in python3 (on linux)?

How to check if a process with that name is running in python3 (on linux)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SergioMaroni, 2019-08-13
@SergioMaroni

for example like this:

import psutil
 
PROCNAME = "httpd"
 
for proc in psutil.process_iter():
    if proc.name() == PROCNAME:
        print proc

first you need to install psutil ( pip install psutil)

L
lorc, 2019-08-13
@lorc

Just like ps does - scan the contents of the "directory" /proc/. All subdirectories of numbers are process ids. Inside the "file" commthe name of the command is stored, and the symlink exepoints to the real binary from which this process was launched.
Although, if you can install additional packages, then of course it's easier to install psuitland not suffer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question