Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

check if a PID exists on a UNIX based system

import os

def pid_exists(pid): 
    if pid < 0: return False #NOTE: pid == 0 returns True
    try:
        os.kill(pid, 0) 
    except ProcessLookupError: # errno.ESRCH
        return False # No such process
    except PermissionError: # errno.EPERM
        return True # Operation not permitted (i.e., process exists)
    else:
        return True # no error, we can send a signal to the process
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #check #PID #exists #UNIX #based #system
ADD COMMENT
Topic
Name
2+6 =