
procpy
procpy - python wrapper for procps library + a module containing higher level classes (with some extensions compared to procps).
Classes procpy module provides
Proc - an instance of Proc class keeps the data gathered from process table (/proc directory) at initialization and does not update it automatically. Thus, you actually work with a copy of process table that might be out of date at the momment of initializing an instance.
ProcRT - an instance of ProcRT class updates its data before accessing given attribute or executing a method. This class is more CPU-time and memory consuming. The gain is that you always have accurate informations about processes running in your system.
Pid - an instance of Pid class works with the data for one process, but it also contains info about its parent.
Some quick details
OS: Linux
Written in: Python and C
Python version: 2.4+
Licence: Apache Licence 2.0
Example
```
!/usr/bin/env python
import os import procpy
a = procpy.Pid(os.getpid()) print "Current process: %s (%d)" % (a.cmd, a.pid) print "Command line args:", a.cmdline print "Executable:", a.exe print "HOME:", a.environ['HOME'] print "Opened files:", a.fds print "Parent: %s (%d)" % (a.parent.cmd, a.parent.pid) print "Parent's executable:", a.parent.exe print "Parent's opened files:", a.parent.fds ```
...and the output:
$ python py.py
Current process: python (17660)
Command line args: ('python', 'py.py')
Executable: /usr/bin/python2.5
HOME: /home/gminick
Opened files: {0: '/dev/pts/6', 1: '/dev/pts/6', 2: '/dev/pts/6', 3: '/proc/uptime', 4: '/proc/meminfo'}
Parent: bash (10932)
Parent's executable: /bin/bash
Parent's opened files: {0: '/dev/pts/6', 1: '/dev/pts/6', 2: '/dev/pts/6', 255: '/dev/pts/6'}
Attributes list of instances of Proc, ProcRT and Pid classes
``` "tid" => task id, the POSIX thread ID (see also: tgid) "ppid" => pid of parent process "pcpu" => %CPU usage (see also pcpustr) "state" => single-char code for process state (S=sleeping) "utime" => user-mode CPU time accumulated by process "stime" => kernel-mode CPU time accumulated by process "cutime" => cumulative utime of process and reaped children "cstime" => cumulative stime of process and reaped children "start_time" => start time of process -- seconds since 1-1-70 "euser" => effective user name "ruser" => real user name "suser" => saved user name "fuser" => filesystem user name "egroup" => effective group name "rgroup" => real group name "sgroup" => saved group name "fgroup" => filesystem group name "cmd" => basename of executable file in call to exec(2) "pgrp" => process group ID "session" => session ID "nlwp" => number of threads, or 0 if no clue "tgid" => task group ID, the POSIX PID (see also: tid) "tty" => full device number of controlling terminal (see also: devnam) "euid" => effective user ID "egid" => effective group ID "ruid" => real user ID "rgid" => real group ID "suid" => saved user ID "tpgid" => terminal process group ID "exit_signal" => might not be SIGCHLD "processor" => current (or most recent?) CPU "environ" => dictionary of environ variables
Procpy specific dictionary keys: "pcpustr" => %CPU usage in #.## format (see also: pcpu) "pmemstr" => %MEM usage in #.## format "ttynam" => name of controlling terminal "cmdline" => full argv of the process as a tuple "start" => start time of process as a tuple: (year, month, day, hour, min, sec, wday, yday, isdst) "time" => accumulated cpu, user and system time as a tuple: (min, sec)
Attributes specific for Pid class: "parent" => an instance of Pid class for the parent PID ```
NOTE: keys description is almost a copy of proc_t struct description from readline.h file (procps/proc/readline.h)
See more at: http://tosh.pl/gminick/
Project Information
- License: Apache License 2.0
- 6 stars
- svn-based source control