summaryrefslogtreecommitdiff
path: root/psutil/_psposix.py
diff options
context:
space:
mode:
authorGiampaolo Rodola' <g.rodola@gmail.com>2013-10-09 16:05:00 +0200
committerGiampaolo Rodola' <g.rodola@gmail.com>2013-10-09 16:05:00 +0200
commitc6024934d5cc19a8f1f991149f249385c5f35a95 (patch)
tree76c39ab2aecdab7abd89535917443e28232375d1 /psutil/_psposix.py
parentd32237191edd425fa1f43107dbe22d3f55b2b347 (diff)
downloadpsutil-c6024934d5cc19a8f1f991149f249385c5f35a95.tar.gz
(POSIX / pid_exists()) - as a follow up of http://stackoverflow.com/questions/568271/how-to-check-if-there-exists-a-process-with-a-given-pid/6940314#comment11929962_6940314 be more explicit in handing os.kill() error codes and raise exception if errcode not in (ESRCH, EPERM)
Diffstat (limited to 'psutil/_psposix.py')
-rw-r--r--psutil/_psposix.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/psutil/_psposix.py b/psutil/_psposix.py
index 8f36fedd..dcb93bdf 100644
--- a/psutil/_psposix.py
+++ b/psutil/_psposix.py
@@ -24,8 +24,19 @@ def pid_exists(pid):
try:
os.kill(pid, 0)
except OSError:
- e = sys.exc_info()[1]
- return e.errno == errno.EPERM
+ err = sys.exc_info()[1]
+ if err.errno == errno.ESRCH:
+ # ESRCH == No such process
+ return False
+ elif err.errno == errno.EPERM:
+ # EPERM clearly means there's a process to deny access to
+ return True
+ else:
+ # According to "man 2 kill" possible error values are
+ # (EINVAL, EPERM, ESRCH) therefore we should bever get
+ # here. If we do let's be explicit in considering this
+ # an error.
+ raise err
else:
return True