Skip to content

Instantly share code, notes, and snippets.

@nileshk
Last active December 15, 2015 09:28
Show Gist options
  • Save nileshk/5238144 to your computer and use it in GitHub Desktop.
Save nileshk/5238144 to your computer and use it in GitHub Desktop.
Find out if a process exists based on PID
import os
import errno
def pid_exists(pid):
"""Check whether pid exists in the current process table."""
if pid < 0:
return False
try:
os.kill(pid, 0)
except OSError, e:
return e.errno == errno.EPERM
else:
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment