Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call Method When New Process Started/Ended #899

Closed
developeralp opened this issue Oct 1, 2016 · 1 comment
Closed

Call Method When New Process Started/Ended #899

developeralp opened this issue Oct 1, 2016 · 1 comment

Comments

@developeralp
Copy link

Hello all,

How can i detect to new process start ?

i.e :

-my application running.
-firefox.exe started
-my.application prints a new line "firefox.exe started !"
-firefox.exe closed
-my.application prints another new line "firefox.exe closed."

I was detecting a process start with that code in c# ;

new ManagementEventWatcher("SELECT * FROM Win32_ProcessStartTrace");

How can i do that in python with psutil ?

@giampaolo
Copy link
Owner

You could iterate over all processes, looking for process name:

import psutil

PROCNAME = "firefox.exe"

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

To check when it's closed you could call is_running ever X secs:

while 1:
        if not proc.is_running():
              print "it's gone"
              break
        time.sleep(1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants