How to check if a process is still running using Python on Linux? [duplicate]
It should work on any POSIX system (although looking at the /proc
filesystem, as others have suggested, is easier if you know it's going to be there).
However: os.kill
may also fail if you don't have permission to signal the process. You would need to do something like:
import sysimport osimport errnotry: os.kill(int(sys.argv[1]), 0)except OSError, err: if err.errno == errno.ESRCH: print "Not running" elif err.errno == errno.EPERM: print "No permission to signal this process!" else: print "Unknown error"else: print "Running"