Skip to content

Instantly share code, notes, and snippets.

@cnsoft
Created June 7, 2013 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cnsoft/5726968 to your computer and use it in GitHub Desktop.
Save cnsoft/5726968 to your computer and use it in GitHub Desktop.
Check whether a process is running or not.
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