summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-01-08 12:41:41 +0000
committerGiampaolo Rodola <g.rodola@gmail.com>2016-01-08 12:41:41 +0000
commitc27ee1d83b2a3057885dc4f4a1ca2eea2bd613d6 (patch)
treeb50e68fa3fa226c6ce26ac2905be24e6d8839382
parente44d5e428c5cd6c31e080dd0830300f1c069b0ca (diff)
downloadpsutil-c27ee1d83b2a3057885dc4f4a1ca2eea2bd613d6.tar.gz
#557 (NetBSD): fix proc status() and num_fds()
-rw-r--r--docs/index.rst9
-rw-r--r--psutil/_common.py7
-rw-r--r--psutil/_psbsd.py28
-rw-r--r--psutil/_psutil_bsd.c15
4 files changed, 32 insertions, 27 deletions
diff --git a/docs/index.rst b/docs/index.rst
index fc43d70a..d71b1193 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -1303,13 +1303,16 @@ Constants
STATUS_DEAD
STATUS_WAKE_KILL
STATUS_WAKING
- STATUS_IDLE
- STATUS_LOCKED
- STATUS_WAITING
+ STATUS_IDLE (OSX, FreeBSD)
+ STATUS_LOCKED (FreeBSD)
+ STATUS_WAITING (FreeBSD)
+ STATUS_SUSPENDED (NetBSD)
A set of strings representing the status of a process.
Returned by :meth:`psutil.Process.status()`.
+ .. versionadded:: 3.4.0: STATUS_SUSPENDED (NetBSD)
+
.. _const-conn:
.. data:: CONN_ESTABLISHED
CONN_SYN_SENT
diff --git a/psutil/_common.py b/psutil/_common.py
index 73ac07bc..3ff1cb88 100644
--- a/psutil/_common.py
+++ b/psutil/_common.py
@@ -43,9 +43,10 @@ STATUS_ZOMBIE = "zombie"
STATUS_DEAD = "dead"
STATUS_WAKE_KILL = "wake-kill"
STATUS_WAKING = "waking"
-STATUS_IDLE = "idle" # BSD
-STATUS_LOCKED = "locked" # BSD
-STATUS_WAITING = "waiting" # BSD
+STATUS_IDLE = "idle" # FreeBSD, OSX
+STATUS_LOCKED = "locked" # FreeBSD
+STATUS_WAITING = "waiting" # FreeBSD
+STATUS_SUSPENDED = "suspended" # NetBSD
CONN_ESTABLISHED = "ESTABLISHED"
CONN_SYN_SENT = "SYN_SENT"
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index 032b87c0..c73f7c8b 100644
--- a/psutil/_psbsd.py
+++ b/psutil/_psbsd.py
@@ -40,7 +40,7 @@ if FREEBSD:
cext.SWAIT: _common.STATUS_WAITING,
cext.SLOCK: _common.STATUS_LOCKED,
}
-elif OPENBSD:
+elif OPENBSD or NETBSD:
PROC_STATUSES = {
cext.SIDL: _common.STATUS_IDLE,
cext.SSLEEP: _common.STATUS_SLEEPING,
@@ -51,6 +51,7 @@ elif OPENBSD:
# psutil.STATUS_DEAD. SDEAD really means STATUS_ZOMBIE.
# cext.SZOMB: _common.STATUS_ZOMBIE,
cext.SDEAD: _common.STATUS_ZOMBIE,
+ cext.SZOMB: _common.STATUS_ZOMBIE,
# From http://www.eecs.harvard.edu/~margo/cs161/videos/proc.h.txt
# OpenBSD has SRUN and SONPROC: SRUN indicates that a process
# is runnable but *not* yet running, i.e. is on a run queue.
@@ -61,15 +62,9 @@ elif OPENBSD:
cext.SRUN: _common.STATUS_WAKING,
cext.SONPROC: _common.STATUS_RUNNING,
}
-elif NETBSD:
- PROC_STATUSES = {
- cext.SIDL: _common.STATUS_IDLE,
- cext.SACTIVE: _common.STATUS_RUNNING,
- cext.SDYING: _common.STATUS_ZOMBIE,
- cext.SSTOP: _common.STATUS_STOPPED,
- cext.SZOMB: _common.STATUS_ZOMBIE,
- cext.SDEAD: _common.STATUS_DEAD,
- }
+
+if NETBSD:
+ PROC_STATUSES[cext.SSUSPENDED] = _common.STATUS_SUSPENDED
TCP_STATUSES = {
cext.TCPS_ESTABLISHED: _common.CONN_ESTABLISHED,
@@ -511,10 +506,8 @@ class Process(object):
@wrap_exceptions
def status(self):
code = cext.proc_status(self.pid)
- if code in PROC_STATUSES:
- return PROC_STATUSES[code]
- # XXX is this legit? will we even ever get here?
- return "?"
+ # XXX is '?' legit? (we're not supposed to return it anyway)
+ return PROC_STATUSES.get(code, '?')
@wrap_exceptions
def io_counters(self):
@@ -574,7 +567,12 @@ class Process(object):
@wrap_exceptions
def num_fds(self):
"""Return the number of file descriptors opened by this process."""
- return cext.proc_num_fds(self.pid)
+ ret = cext.proc_num_fds(self.pid)
+ if NETBSD:
+ # On NetBSD the underlying C function does not raise NSP
+ # in case the process is gone.
+ self.name() # raise NSP if the process disappeared on us
+ return ret
else:
num_fds = _not_implemented
diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c
index a621afc2..5d22d881 100644
--- a/psutil/_psutil_bsd.c
+++ b/psutil/_psutil_bsd.c
@@ -1077,12 +1077,15 @@ void init_psutil_bsd(void)
PyModule_AddIntConstant(module, "SDEAD", SDEAD);
PyModule_AddIntConstant(module, "SONPROC", SONPROC);
#elif defined(__NetBSD__)
- PyModule_AddIntConstant(module, "SIDL", SIDL);
- PyModule_AddIntConstant(module, "SACTIVE", SACTIVE);
- PyModule_AddIntConstant(module, "SDYING", SDYING);
- PyModule_AddIntConstant(module, "SSTOP", SSTOP);
- PyModule_AddIntConstant(module, "SZOMB", SZOMB);
- PyModule_AddIntConstant(module, "SDEAD", SDEAD);
+ PyModule_AddIntConstant(module, "SIDL", LSIDL);
+ PyModule_AddIntConstant(module, "SRUN", LSRUN);
+ PyModule_AddIntConstant(module, "SSLEEP", LSSLEEP);
+ PyModule_AddIntConstant(module, "SSTOP", LSSTOP);
+ PyModule_AddIntConstant(module, "SZOMB", LSZOMB);
+ PyModule_AddIntConstant(module, "SDEAD", LSDEAD);
+ PyModule_AddIntConstant(module, "SONPROC", LSONPROC);
+ // unique to NetBSD
+ PyModule_AddIntConstant(module, "SSUSPENDED", LSSUSPENDED);
#endif
// connection status constants