Created
June 7, 2013 03:52
-
-
Save cnsoft/5726968 to your computer and use it in GitHub Desktop.
Check whether a process is running or not.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
import re | |
def findThisProcess( process_name ): | |
ps = subprocess.Popen("ps -eaf | grep "+process_name, shell=True, stdout=subprocess.PIPE) | |
output = ps.stdout.read() | |
ps.stdout.close() | |
ps.wait() | |
return output | |
# This is the function you can use | |
def isThisRunning( process_name ): | |
output = findThisProcess( process_name ) | |
if re.search('path/of/process'+process_name, output) is None: | |
return False | |
else: | |
return True | |
# Example of how to use | |
if isThisRunning('some_process') == False: | |
print("Not running") | |
else: | |
print("Running!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment