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

This version

0.4.0

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.0.tar.gz (167.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

psutil-0.4.0.win-amd64-py3.4.exe (302.6 kB view details)

Uploaded Source

psutil-0.4.0.win-amd64-py3.3.exe (301.7 kB view details)

Uploaded Source

psutil-0.4.0.win-amd64-py2.7.exe (302.8 kB view details)

Uploaded Source

psutil-0.4.0.win32-py3.4.exe (268.0 kB view details)

Uploaded Source

psutil-0.4.0.win32-py3.3.exe (268.0 kB view details)

Uploaded Source

psutil-0.4.0.win32-py2.7.exe (272.8 kB view details)

Uploaded Source

psutil-0.4.0.win32-py2.6.exe (273.3 kB view details)

Uploaded Source

psutil-0.4.0.win32-py2.5.exe (140.8 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for psutil-0.4.0.tar.gz
Algorithm Hash digest
SHA256 4b0ecc77d6c503449af3d2f0a41ad4cb8338e173f5d655a8239e41b1a49bc278
MD5 4465196d7a6d0fc4295776ee3e7b43ec
BLAKE2b-256 8846a933ab20c6d9b0ca5704b60307b9e80bdc119b759e89b74a2609b4c10eb6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for psutil-0.4.0.win-amd64-py3.4.exe
Algorithm Hash digest
SHA256 94d2d0a24fa62f5655e9e21dd558592bf1d3d515d944eee70e9cd2e2bf2bf244
MD5 2d1507aeea5b3a7c38591cc6e87c3f12
BLAKE2b-256 7c5bd9057a158b09c377eab80dae60928f8fe29bdd11635ca725098587981eeb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for psutil-0.4.0.win-amd64-py3.3.exe
Algorithm Hash digest
SHA256 9ee193dec84c2c91ac8712760eaaae0488dee92db37134dfcddc889ecd4f578d
MD5 b8f0766413d6d890a07ed5e2db72b766
BLAKE2b-256 acebf6923ea1b46803251f2bb42ad9b8ed90f4b8d04cdb2384c9ea535193e4f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for psutil-0.4.0.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 9689512e5a32508216bd6cc7cb2fbe938e4a47b483cd345b5bec6dda790a9210
MD5 8702738009d71042084ae4f66fdf98f7
BLAKE2b-256 a5063ca1c85b733ceaced144cb211c1fc40a6b3b1c4f7a109bbb8e19fe09eac0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for psutil-0.4.0.win32-py3.4.exe
Algorithm Hash digest
SHA256 5b63e0e83dde30d62206497320c06b27c489ffb261e95ac1267b7a1b8d4ce72d
MD5 9baaa984711eb3220e7718c93b22fa9b
BLAKE2b-256 b48e028b849600447c45c20582d7ddae1e39d31b83799289f54f1b79af664295

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for psutil-0.4.0.win32-py3.3.exe
Algorithm Hash digest
SHA256 dfe18b8eb9ee6dbbd49e28f245794c2fc22b56d770038668cb6e112935c49927
MD5 e1ca0a84590762cfb1717f692def6778
BLAKE2b-256 f42b13be095a72c83fdbe11d519310cb34ff8e442d72ab52691218a83c216ac4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for psutil-0.4.0.win32-py2.7.exe
Algorithm Hash digest
SHA256 5b6cbf5aaeab55db1d9657fc75e4b54fa94d17d03ca97c94aa150e1bfdc8fb2e
MD5 cf3a8688c55d926b4b6c662734b57593
BLAKE2b-256 7d38b719c8867699a71a98e92e61fd1b0f12bad997a9de60bf8f6215184692e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for psutil-0.4.0.win32-py2.6.exe
Algorithm Hash digest
SHA256 ca511f56db8f1586612851a2eedbf80e38cf29f4a98f133410a74da284822747
MD5 dd0566cc89c6723c23ad2e01b81c19ef
BLAKE2b-256 b45678f182bf9c81a978067ba5447eca2ea70ef2bc9ac94228adfae5428cd108

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for psutil-0.4.0.win32-py2.5.exe
Algorithm Hash digest
SHA256 fab822fb8968b45695174a2c9b4d40e9ae81126343e24d38b627036579f1ee5e
MD5 39f78f16a14672531230f620253ea46f
BLAKE2b-256 071e7827d1271248ddef694681747297aeb3f77dafe5c93ff707a625e3947082

See more details on using hashes here.

Supported by

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