Skip to main content

A process utilities module for Python

Project description

Summary

psutil is a module providing an interface for retrieving information on all running processes and system utilization (CPU, disk, memory) in a portable way by using Python, implementing many functionalities offered by command line tools such as: ps, top, df, kill, free, lsof, free, netstat, ifconfig, nice, ionice, iostato, iotop, uptime, tty.

It currently supports Linux, Windows, OSX and FreeBSD both 32-bit and 64-bit with Python versions from 2.4 to 3.3 by using a single code base.

Example usages

CPU

>>> import psutil
>>> psutil.cpu_times()
cputimes(user=3961.46, nice=169.729, system=2150.659, idle=16900.540,
         iowait=629.509, irq=0.0, softirq=19.422)
>>>
>>> for x in range(3):
...     psutil.cpu_percent(interval=1)
...
4.0
5.9
3.8
>>>
>>> for x in range(3):
...     psutil.cpu_percent(interval=1, percpu=True)
...
[4.0, 6.9]
[7.0, 8.5]
[1.2, 9.0]
>>>

Memory

>>> psutil.phymem_usage()
usage(total=4153868288, used=2854199296, free=1299668992, percent=34.6)
>>> psutil.virtmem_usage()
usage(total=2097147904, used=4096, free=2097143808, percent=0.0)
>>>

Disks

>>> psutil.disk_partitions()
[partition(device='/dev/sda1', mountpoint='/', fstype='ext4'),
 partition(device='/dev/sda2', mountpoint='/home', fstype='ext4')]
>>>
>>> psutil.disk_usage('/')
usage(total=21378641920, used=4809781248, free=15482871808, percent=22.5)
>>>
>>> psutil.disk_io_counters()
iostat(read_count=719566, write_count=1082197, read_bytes=18626220032,
       write_bytes=24081764352, read_time=5023392, write_time=63199568)
>>>

Network

>>> psutil.network_io_counters(pernic=True)
{'lo': iostat(bytes_sent=799953745, bytes_recv=799953745,
              packets_sent=453698, packets_recv=453698),
 'eth0': iostat(bytes_sent=734324837, bytes_recv=4163935363,
                packets_sent=3605828, packets_recv=4096685)}
>>>

Process 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.exe
'/usr/bin/python'
>>> p.getcwd()
'/home/giampaolo'
>>> p.cmdline
['/usr/bin/python', 'main.py']
>>>
>>> str(p.status)
'running'
>>> p.username
'giampaolo'
>>> p.create_time
1267551141.5019531
>>> p.terminal
'/dev/pts/0'
>>>
>>> p.uids
user(real=1000, effective=1000, saved=1000)
>>> p.gids
group(real=1000, effective=1000, saved=1000)
>>>
>>> p.get_cpu_percent(interval=1.0)
12.1
>>> p.get_memory_percent()
0.63423
>>>
>>> p.get_memory_info()
meminfo(rss=7471104, vms=68513792)
>>> p.get_cpu_times()
cputimes(user=1.02, system=0.31)
>>>
>>> p.get_io_counters()
io(read_count=478001, write_count=59371, read_bytes=700416, write_bytes=69632)
>>>
>>> p.get_open_files()
[openfile(path='/home/giampaolo/svn/psutil/somefile', fd=3)]
>>>
>>> p.get_connections()
[connection(fd=115, family=2, type=1, local_address=('10.0.0.1', 48776),
            remote_address=('93.186.135.91', 80), status='ESTABLISHED'),
 connection(fd=117, family=2, type=1, local_address=('10.0.0.1', 43761),
            remote_address=('72.14.234.100', 80), status='CLOSING'),
 connection(fd=119, family=2, type=1, local_address=('10.0.0.1', 60759),
            remote_address=('72.14.234.104', 80), status='ESTABLISHED'),
 connection(fd=123, family=2, type=1, local_address=('10.0.0.1', 51314),
            remote_address=('72.14.234.83', 443), status='SYN_SENT')]
>>>
>>> p.get_threads()
[thread(id=5234, user_time=22.5, system_time=9.2891),
 thread(id=5235, user_time=0.0, system_time=0.0),
 thread(id=5236, user_time=0.0, system_time=0.0),
 thread(id=5237, user_time=0.0707, system_time=1.1)]
>>>
>>> p.nice
0
>>> p.nice = 10  # set/change process priority
>>> p.nice
10
>>>
>>> p.suspend()
>>> p.resume()
>>>
>>> p.terminate()
>>> p.wait(timeout=3)
0
>>>
>>> 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.1  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  1.1  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.3  1.1    5432    3072 17:55    00:00 -su
0       28655  0.0  1.0    4932    3204 21:58    00:00 python _psutil.py
>>>

Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

psutil-0.4.1.tar.gz (171.5 kB view details)

Uploaded Source

Built Distributions

psutil-0.4.1.win-amd64-py3.4.exe (310.1 kB view details)

Uploaded Source

psutil-0.4.1.win-amd64-py3.3.exe (309.2 kB view details)

Uploaded Source

psutil-0.4.1.win-amd64-py2.7.exe (310.4 kB view details)

Uploaded Source

psutil-0.4.1.win32-py3.4.exe (275.6 kB view details)

Uploaded Source

psutil-0.4.1.win32-py3.3.exe (275.7 kB view details)

Uploaded Source

psutil-0.4.1.win32-py2.7.exe (280.4 kB view details)

Uploaded Source

psutil-0.4.1.win32-py2.6.exe (280.9 kB view details)

Uploaded Source

psutil-0.4.1.win32-py2.5.exe (148.5 kB view details)

Uploaded Source

File details

Details for the file psutil-0.4.1.tar.gz.

File metadata

  • Download URL: psutil-0.4.1.tar.gz
  • Upload date:
  • Size: 171.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for psutil-0.4.1.tar.gz
Algorithm Hash digest
SHA256 33002c38f916835c949ae39a84f3f6d09ce01818ed805dfd61f8f3844c395c9d
MD5 5e29907cec9d341237ca271c569bf492
BLAKE2b-256 a0cd00550e16a2a0357a9c24946160e60fc947bbe23bc276aff1b4d3e7b90345

See more details on using hashes here.

File details

Details for the file psutil-0.4.1.win-amd64-py3.4.exe.

File metadata

File hashes

Hashes for psutil-0.4.1.win-amd64-py3.4.exe
Algorithm Hash digest
SHA256 fc75e094cf573a7b9977be2a9d3a9d94671bc0ab098d52c391dd63227309cbea
MD5 74af92b38ed47ca8e553e97cac5ef762
BLAKE2b-256 cde69f963b32ab254b8c2bbedf5ce543cace8b08054924fd26fa233f99863ecc

See more details on using hashes here.

File details

Details for the file psutil-0.4.1.win-amd64-py3.3.exe.

File metadata

File hashes

Hashes for psutil-0.4.1.win-amd64-py3.3.exe
Algorithm Hash digest
SHA256 457cfdecbf63f813bf86e2f736ab3b20447e8d8c2c516dd2a13a7463177f8bc6
MD5 051a3efea2e761d71412c60ba3f23478
BLAKE2b-256 6e9e6c7f5baf2529d9bba563cdff0b81413b5870b0681739318112adecd99ad0

See more details on using hashes here.

File details

Details for the file psutil-0.4.1.win-amd64-py2.7.exe.

File metadata

File hashes

Hashes for psutil-0.4.1.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 3e408028898b4ad09c207659c1b6cb8e6a74fb39ab3157b761e057a629118fec
MD5 0df0344ad53d7e51220d5fde912ce01a
BLAKE2b-256 06753dc33773b1a1f7055b24245a0c8bec4d5776f1e1125329a13e82449007be

See more details on using hashes here.

File details

Details for the file psutil-0.4.1.win32-py3.4.exe.

File metadata

File hashes

Hashes for psutil-0.4.1.win32-py3.4.exe
Algorithm Hash digest
SHA256 860a039b67ee015a6304e8d05e6dc5c2a447eca331b7d6c9d04f41d7f2fc3a66
MD5 643191172a0aa4a6fd65aef7280c6a3b
BLAKE2b-256 c5b7d2662ebf114961766c9eb3d9b737cb5541060d35e65b542b0acef470221a

See more details on using hashes here.

File details

Details for the file psutil-0.4.1.win32-py3.3.exe.

File metadata

File hashes

Hashes for psutil-0.4.1.win32-py3.3.exe
Algorithm Hash digest
SHA256 a35ce124b2dec01d7632627c9370f5202978fce89ae59235cf4d5e05bbd0e02b
MD5 3eaba85011bd25e7778b5941220d4398
BLAKE2b-256 387d407f7586bccdeb80f5da82d8ebb98712bfcc7217e3d7c3fc61b3bba893f2

See more details on using hashes here.

File details

Details for the file psutil-0.4.1.win32-py2.7.exe.

File metadata

File hashes

Hashes for psutil-0.4.1.win32-py2.7.exe
Algorithm Hash digest
SHA256 cefad502010c78425190498efc54541ae7bbe9eaa73ef4000cf11b032d32a8bb
MD5 aae9ad6b466d3085bab177d3f3859cab
BLAKE2b-256 c6c414807de009a1beab2426b537379a8b05b1d69fef1fde7e23581cc332cdb3

See more details on using hashes here.

File details

Details for the file psutil-0.4.1.win32-py2.6.exe.

File metadata

File hashes

Hashes for psutil-0.4.1.win32-py2.6.exe
Algorithm Hash digest
SHA256 aafe9e328ffc173b26c78897c168858da335c85d4a02d666ad68fe2fe14601d1
MD5 60620bc9c5b12d50851d9fd9378757a9
BLAKE2b-256 1ea1594bf54e7c4056bc5284023be97f67c930175b3329e086a4ed8966cb067a

See more details on using hashes here.

File details

Details for the file psutil-0.4.1.win32-py2.5.exe.

File metadata

File hashes

Hashes for psutil-0.4.1.win32-py2.5.exe
Algorithm Hash digest
SHA256 ef4ed886b4d2d664fab5c369543690cda04e04a3b7496d72e369ef5240a8af6b
MD5 50dd9d5c2321302969e9b18b8a548c77
BLAKE2b-256 65ade7828797558dd5f209694b02ce079cd3b6beacf6a5175f38c1973c688494

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page