G
G
GoshaLaz2022-04-20 23:09:21
Python
GoshaLaz, 2022-04-20 23:09:21

How can you track if a program or applications is open in python?

Do you need python to track the opening of a program?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2022-04-21
@GoshaLaz

If open program means "is there an application process running", then this can be checked by getting a list of all running processes using psutil:
https://psutil.readthedocs.io/en/latest/#functions

D
Daniil Igumenshev, 2022-04-20
@senku1435

Sending a signal 0 to pid will throw an OSError exception if pid is not running and will do nothing otherwise.

import os

def check_pid(pid):        
    """ Check For the existence of a unix pid. """
    try:
        os.kill(pid, 0)
    except OSError:
        return False
    else:
        return True

https://stackoverflow.com/questions/568271/how-to-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question