Package: proc
The Python packageprocexposes process information available in the Linuxprocess information pseudo-file systemavailable at/proc. Theprocpackage is currently tested on cPython 2.7, 3.5+ and PyPy (2.7). The automated
test suite regularly runs on Ubuntu Linux but other Linux variants (also those
not based on Debian Linux) should work fine. For usage instructions please
refer to thedocumentation.InstallationDesign choicesHistorySimilar projectsContactLicenseInstallationTheprocpackage is available onPyPIwhich means installation should be as
simple as:$pipinstallprocThere’s actually a multitude of ways to install Python packages (e.g. theper
user site-packages directory,virtual environmentsor just installing
system wide) and I have no intention of getting into that discussion here, so
if this intimidates you then read up on your options before returning to these
instructions ;-).Once you’ve installed theprocpackage head over to thedocumentationfor
some examples of how theprocpackage can be used.Design choicesTheprocpackage was created with the following considerations in mind:Completely specialized to LinuxIt parses/procand nothing else ;-).Fully implemented in PythonNo binary/compiled components, as opposed topsutilwhich is way more
portable but requires a compiler for installation.Very well documentedThe documentation should make it easy to get started (as opposed toprocfswhich I evaluated and eventually gave up on because I had to resort to reading
through its source code just to be disappointed in its implementation).Robust implementationReading/procis inherently sensitive to race conditions and theprocpackage takes this into account, in fact the test suite contains a test that
creates race conditions in order to verify that they are handled correctly.
The API of theprocpackage hides race conditions as much as possible and
where this is not possible the consequences are clearly documented.Layered API design(where each layer is documented)Builds higher level abstractions on top of lower level abstractions:The proc.unix moduleDefines a simple process class that combines process IDs and common UNIX
signals to implement process control primitives like waiting for a process to
end and gracefully or forcefully terminating a process.The proc.core moduleBuilds on top of theproc.unixmodule to provide a simple, fast and easy
to use API for the process information available in/proc. If you’re
looking for a simple and/or fast interface to/procthat does the heavy
lifting (parsing) for you then this is what you’re looking for.The proc.tree moduleBuilds on top of theproc.coremodule to provide an in-memory tree data
structure that mimics the actual process tree, enabling easy searching and
navigation through the process tree.The proc.apache moduleBuilds on top of theproc.treemodule to implement an easy to use Python
API that does metrics collection for monitoring of Apache web server worker
memory usage, including support for WSGI process groups.The proc.cron moduleImplements the command line programcron-gracefulwhich gracefully
terminates cron daemons. This module builds on top of theproc.treemodule as a demonstration of the possibilities of theprocpackage and as a
practical tool that is ready to be used on any Linux system that has Python
andcroninstalled.The proc.notify moduleImplements the command line programnotify-send-headlesswhich can be
used to run the programnotify-sendin headless environments like cron
jobs and system daemons.HistoryI’ve been writing shell and Python scripts that parse/procfor years now
(it seems so temptingly easy when you get started ;-). Sometimes I resorted to
copy/pasting snippets of Python code between personal and work projects because
the code was basically done, just not available in an easy to share form.Once I started fixing bugs in diverging copies of that code I decided it was
time to combine all of the features I’d grown to appreciate into a single well
tested and well documented Python package with an easy to use API and share it
with the world.This means that, although I made my first commit on theprocpackage in March
2015, much of its code has existed for years in various forms.Similar projectsBelow are several other Python libraries that expose process information. If
theprocpackage isn’t working out for you consider trying one of these. The
summaries are copied and/or paraphrased from the documentation of each
package:psutilA cross-platform library for retrieving information on running processes and
system utilization (CPU, memory, disks, network) in Python.procpyA Python wrapper for theprocpslibrary and a module containing higher level
classes (with some extensions compared toprocps).procfsPython API for the Linux/procvirtual filesystem.ContactThe latest version ofprocis available onPyPIandGitHub. The
documentation is hosted onRead the Docsand includes achangelog. For bug
reports please create an issue onGitHub. If you have questions, suggestions,
etc. feel free to send me an e-mail atpeter@peterodding.com.LicenseThis software is licensed under theMIT license.© 2020 Peter Odding.