N
N
Nikita Yaremenko2020-08-11 19:55:25
Python
Nikita Yaremenko, 2020-08-11 19:55:25

How to find out if a process is running in the task manager?

You need to find out if the process is running in the task manager, and therefore return either True or False.
I am using the psutil library. There is the following code:

proc_name = 'chrome.exe'
sucsesful = False
        for proc in psutil.process_iter():
            try:
                if proc.name() == proc_name:
                    sucsesful = True
                    break
             except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): 
                   continue
        if not sucsesful:
           print("chrome hasn`t started")
        else:
             print('chrome started')

Even when the chrome.exe process is running, sucsesful = False.
Why is that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2020-08-20
@tumbler

You are still iterating through all the processes, why not print their names? Surely there will be something similar, but slightly different fromchrome.exe

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question