Python process utilities (psutil)

Summary

psutil is a module providing an interface for retrieving information on running processes and system utilization (CPU, memory) in a portable way by using Python.

It currently supports Linux, OS X, FreeBSD and Windows.

Example usage

>>> import psutil
>>> psutil.get_pid_list()
[1, 2, 3, 4, 5, 6, 7, 46, 48, 50, 51, 178, 182, 222, 223, 224,
268, 1215, 1216, 1220, 1221, 1243, 1244, 1301, 1601, 2237, 2355,
2637, 2774, 3932, 4176, 4177, 4185, 4187, 4189, 4225, 4243, 4245,
4263, 4282, 4306, 4311, 4312, 4313, 4314, 4337, 4339, 4357, 4358,
4363, 4383, 4395, 4408, 4433, 4443, 4445, 4446, 5167, 5234, 5235,
5252, 5318, 5424, 5644, 6987, 7054, 7055, 7071]
>>> p = psutil.Process(7055)
>>> p.name
'python'
>>> p.path
'/usr/bin'
>>> p.cmdline
['/usr/bin/python', '-O']
>>> p.uid
1000
>>> p.gid
1000
>>> rss, vms =  p.get_memory_info()
>>> print "Resident memory: %s KB" %(rss / 1024)
Resident memory: 3768 KB
>>> print "Virtual memory: %s KB" %(vms / 1024)
Virtual memory: 6176 KB
>>>
>>> psutil.test()
UID       PID %CPU %MEM     VSZ     RSS START     TIME COMMAND
0           0  0.0  0.0       0       0 Mar20    00:00 [sched]
0           1  0.0  0.3    1740     600 Mar20    00:04 /sbin/init
0           2  0.0  0.0       0       0 Mar20    00:00 [kthreadd]
0           3  0.0  0.0       0       0 Mar20    00:00 [migration/0]
0           4  0.0  0.0       0       0 Mar20    00:05 [ksoftirqd/0]
0           5  0.0  0.0       0       0 Mar20    00:00 [watchdog/0]
0           6  0.0  0.0       0       0 Mar20    00:03 [events/0]
0           7  0.0  0.0       0       0 Mar20    00:00 [khelper]
0          46  0.0  0.0       0       0 Mar20    00:00 [kintegrityd/0]
0          48  0.0  0.0       0       0 Mar20    00:01 [kblockd/0]
0          50  0.0  0.0       0       0 Mar20    00:00 [kacpid]
0          51  0.0  0.0       0       0 Mar20    00:00 [kacpi_notify]
0         179  0.0  0.0       0       0 Mar20    00:00 [cqueue]
0         183  0.0  0.0       0       0 Mar20    00:00 [kseriod]
0         223  0.0  0.0       0       0 Mar20    00:00 [pdflush]
0         224  0.0  0.0       0       0 Mar20    00:04 [pdflush]
0         225  0.0  0.0       0       0 Mar20    00:01 [kswapd0]
0         269  0.0  0.0       0       0 Mar20    00:00 [aio/0]
0        1221  0.0  0.0       0       0 Mar20    00:00 [ksuspend_usbd]
0        1222  0.0  0.0       0       0 Mar20    00:00 [khubd]
0        1226  0.0  0.0       0       0 Mar20    00:00 [ata/0]
0        1227  0.0  0.0       0       0 Mar20    00:00 [ata_aux]
0        1245  0.0  0.0       0       0 Mar20    00:04 [mpt_poll_0]
0        1402  0.0  0.0       0       0 Mar20    00:00 [scsi_eh_0]
0        1843  0.0  0.0       0       0 Mar20    00:00 [scsi_eh_1]
0        1844  0.0  0.0       0       0 Mar20    00:00 [scsi_eh_2]
0        2241  0.0  0.0       0       0 Mar20    00:06 [kjournald]
0        2359  0.0  0.4    2312     740 Mar20    00:02 /sbin/udevd --daemon
0        2678  0.0  0.0       0       0 Mar20    00:00 [kgameportd]
0        2796  0.0  0.0       0       0 Mar20    00:00 [kpsmoused]
0        4209  0.0  0.3    1780     536 Mar20    00:00 /sbin/getty 38400 tty4
0        4210  0.0  0.3    1780     536 Mar20    00:00 /sbin/getty 38400 tty5
0        4215  0.0  0.3    1780     540 Mar20    00:00 /sbin/getty 38400 tty2
0        4216  0.0  0.3    1780     540 Mar20    00:00 /sbin/getty 38400 tty3
0        4217  0.0  0.3    1780     540 Mar20    00:00 /sbin/getty 38400 tty6
101      4258  0.0  0.4    2012     712 Mar20    00:01 /sbin/syslogd -u syslog
0        4276  0.0  0.4    1936     544 Mar20    00:00 /bin/dd bs 1 if /proc/kmsg of /var/run/klogd/kmsg
102      4278  0.0  0.7    3508    2248 Mar20    00:00 /sbin/klogd -P /var/run/klogd/kmsg
104      4296  0.0  0.5    2640     844 Mar20    00:02 /bin/dbus-daemon --system
0        4315  0.0  1.0    5392    1060 Mar20    00:00 /usr/sbin/sshd
0        4349  0.0  1.8    9216    1464 Mar20    00:01 /usr/sbin/winbindd
0        4363  0.0  1.8    9472    2000 Mar20    00:00 /usr/sbin/winbindd
0        4364  0.0  1.8    9216    1012 Mar20    00:00 /usr/sbin/winbindd
0        4365  0.0  0.4    2064     452 Mar20    00:00 /usr/sbin/atd
0        4390  0.0  0.7    3408    1016 Mar20    00:00 /usr/sbin/cron
0        4400  0.0  1.6    8128    3212 Mar20    00:00 /bin/login --
0        4402  0.0  1.8    9216    1108 Mar20    00:00 /usr/sbin/winbindd
1000     5213  0.0  1.1    5656    3032 Mar20    00:00 -bash
0        5232  0.0  1.6    8144    2316 Mar20    00:00 su -
0        5298  0.0  0.8    4220    1832 Mar20    00:00 -su
0        5342  0.0  0.4    2252     644 Mar20    00:00 dhclient
0       13234  0.0  1.6    8120    1580 00:38    00:02 /usr/sbin/nmbd -D
0       13236  0.0  2.6   13604    2816 00:38    00:00 /usr/sbin/smbd -D
0       13239  0.0  2.6   13604    1044 00:38    00:00 /usr/sbin/smbd -D
0       23643  0.0  2.4   12376    4280 14:43    00:00 sshd: user [priv]
1000    23648  0.0  2.4   12512    2008 14:43    00:06 sshd: user@pts/2
1000    23649  0.0  1.2    5944    3340 14:43    00:00 -bash
0       25860  0.0  1.6    8144    2300 17:55    00:00 su -
0       25926  0.0  1.1    5432    3072 17:55    00:00 -su
1000    28464  0.0  2.7   13968    4076 21:45    00:00 /usr/sbin/smbd -D
0       28655  0.0  1.0    4932    3204 21:58    00:00 python _psutil.py
>>>

Current Status

As of 2009-01-27 psutil is released to the general public. The current release (0.1.2) should be considered a beta release. No known bugs exist currently and all releases are fully tested with unit-tests and automated test scripts. However, the psutil library has not been extensively tested by enough users in real-world environments to be considered rock-solid production code. Bug reports and patches welcome!

Mailing lists

Users
http://groups.google.com/group/psutil/topics

Developers
http://groups.google.com/group/psutil-dev/topics

SVN commits and issue tracker changes
http://groups.google.com/group/psutil-commits/topics