diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-09-10 10:34:22 +0800 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-09-10 10:34:22 +0800 |
commit | c604a55694cc70d54f7abea628d41d99842944cc (patch) | |
tree | b09a6dbfd9e3cc42f275ff503597528f7d5193e7 | |
parent | 5de6f62fd70b1e058b67781c9812f1ac57736fd9 (diff) | |
download | psutil-c604a55694cc70d54f7abea628d41d99842944cc.tar.gz |
#1102: implement is64bit() on FreeBSD
-rw-r--r-- | docs/index.rst | 10 | ||||
-rw-r--r-- | psutil/_psbsd.py | 10 | ||||
-rw-r--r-- | psutil/_psutil_bsd.c | 2 | ||||
-rw-r--r-- | psutil/arch/freebsd/specific.c | 35 | ||||
-rw-r--r-- | psutil/arch/freebsd/specific.h | 3 |
5 files changed, 53 insertions, 7 deletions
diff --git a/docs/index.rst b/docs/index.rst index a75b9323..36123d96 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1859,13 +1859,13 @@ Process class .. method:: is64bit() - Return ``True`` if this is a 64 bit process, ``False`` if not, ``None`` if - it cannot be determined. It can be assumed that ``False`` means 32 bit - unless you have a very old or exotic hardware. + Return ``True`` if this is a 64-bit process, ``False`` if not, ``None`` if + undetermined. It can be assumed that ``False`` means 32-bit unless you have + a very old or exotic hardware. - Availability: Linux, Windows, OSX + Availability: Linux, Windows, OSX, FreeBSD - .. versionadded:: 5.3.0 + .. versionadded:: 5.4.0 .. method:: is_running() diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py index fe55f92f..da264ef3 100644 --- a/psutil/_psbsd.py +++ b/psutil/_psbsd.py @@ -870,3 +870,13 @@ class Process(object): @wrap_exceptions def memory_maps(self): return cext.proc_memory_maps(self.pid) + + @wrap_exceptions + def is64bit(self): + name = cext.proc_abi_vector(self.pid) + if name in ("FreeBSD ELF64", "Linux ELF64"): + return True + elif name in ("FreeBSD ELF32", "Linux ELF32"): + return False + else: + return None diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c index 3527b666..64e1e7f7 100644 --- a/psutil/_psutil_bsd.c +++ b/psutil/_psutil_bsd.c @@ -945,6 +945,8 @@ PsutilMethods[] = { "Set process CPU affinity."}, {"cpu_count_phys", psutil_cpu_count_phys, METH_VARARGS, "Return an XML string to determine the number physical CPUs."}, + {"proc_abi_vector", psutil_proc_abi_vector, METH_VARARGS, + "Return process ABI vector name (to check process bitness)"}, #endif // --- system-related functions diff --git a/psutil/arch/freebsd/specific.c b/psutil/arch/freebsd/specific.c index 8d09ad89..006c813c 100644 --- a/psutil/arch/freebsd/specific.c +++ b/psutil/arch/freebsd/specific.c @@ -1007,3 +1007,38 @@ error: PyErr_SetFromErrno(PyExc_OSError); return NULL; } + + +/* + * Return process ABI vector name (to check process bitness). + */ +PyObject * +psutil_proc_abi_vector(PyObject *self, PyObject *args) { + long pid; + size_t len; + int error; + int mib[4]; + char progt[32]; + size_t i; + len = sizeof(progt); + + if (! PyArg_ParseTuple(args, "l", &pid)) + return NULL; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_SV_NAME; + mib[3] = pid; + error = sysctl(mib, 4, progt, &len, NULL, 0); + + if (error == -1) { + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + if (len == 0) { + PyErr_SetString(PyExc_RuntimeError, "size mismatch"); + return NULL; + } + + return Py_BuildValue("s", progt); +} diff --git a/psutil/arch/freebsd/specific.h b/psutil/arch/freebsd/specific.h index 0df66ecc..588abe8a 100644 --- a/psutil/arch/freebsd/specific.h +++ b/psutil/arch/freebsd/specific.h @@ -27,6 +27,5 @@ PyObject* psutil_proc_threads(PyObject* self, PyObject* args); PyObject* psutil_swap_mem(PyObject* self, PyObject* args); PyObject* psutil_virtual_mem(PyObject* self, PyObject* args); PyObject* psutil_cpu_stats(PyObject* self, PyObject* args); -#if defined(PSUTIL_FREEBSD) PyObject* psutil_sensors_battery(PyObject* self, PyObject* args); -#endif +PyObject* psutil_proc_abi_vector(PyObject* self, PyObject* args); |