Summarypsutil is a module providing an interface for retrieving information on running processes and system utilization (CPU, memory) in a portable way by using Python, implementing many functionalities offered by command line tools like ps, top, kill and Windows task manager. It currently supports Linux, OS X, FreeBSD and Windows with Python versions from 2.4 to 3.1 by using a unique code base. Example usageprocess management>>> 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', 'run.py'] >>> p.uid 1000 >>> p.gid 1000 >>> p.username 'jake' >>> p.create_time 1267551141.5019531 >>> p.get_cpu_percent() 12.31243 >>> p.get_memory_percent() 0.63423 >>> rss, vms = p.get_memory_info() >>> "Resident memory: %s KB" %(rss / 1024) 'Resident memory: 3768 KB' >>> "Virtual memory: %s KB" %(vms / 1024) 'Virtual memory: 6176 KB' >>> >>> p.suspend() >>> p.resume() >>> psutil.test() UID PID %CPU %MEM VSZ RSS START TIME COMMAND 0 0 0.0 0.0 0 0 00:12 00:00 [sched] 0 1 0.0 0.3 1740 600 00:12 00:04 /sbin/init 0 2 0.0 0.0 0 0 00:12 00:00 [kthreadd] 0 3 0.0 0.0 0 0 00:12 00:00 [migration/0] ... 0 13239 0.0 2.6 13604 1044 00:38 00:00 /usr/sbin/smbd -D 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 25926 0.0 1.1 5432 3072 17:55 00:00 -su 0 28655 0.0 1.0 4932 3204 21:58 00:00 python _psutil.py >>> System monitoring (CPU and memory)>>> import psutil, time >>> print psutil.cpu_times() softirq=50.87; iowait=39.63; system=1130.67; idle=164171.41; user=965.15; irq=7.08; nice=0.0 >>> >>> while 1: ... print round(psutil.cpu_percent(), 1) ... time.sleep(1) ... 5.4 3.2 7.3 7.1 2.5 Traceback (most recent call last): File "<stdin>", line 3, in <module> KeyboardInterrupt >>> >>> psutil.TOTAL_PHYMEM 526458880 >>> psutil.avail_phymem() 153530368 >>> psutil.total_virtmem() 197365760 >>> psutil.avail_virtmem() 194277376 Mailing listsUsers Developers SVN commits and issue tracker changes ContributeIf you want to help or just give us suggestions about the project and other related things, subscribe to the discussion mailing list. If you want to talk with project team members about psutil and other related things feel free to contact us at the following addresses:
Feedbacks and suggestions are greatly appreciated as well as new testers and coders willing to join the development. Thank you. |