METADATA 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. Metadata-Version: 2.1
  2. Name: psutil
  3. Version: 5.7.3
  4. Summary: Cross-platform lib for process and system monitoring in Python.
  5. Home-page: https://github.com/giampaolo/psutil
  6. Author: Giampaolo Rodola
  7. Author-email: g.rodola@gmail.com
  8. License: BSD
  9. Keywords: ps,top,kill,free,lsof,netstat,nice,tty,ionice,uptime,taskmgr,process,df,iotop,iostat,ifconfig,taskset,who,pidof,pmap,smem,pstree,monitoring,ulimit,prlimit,smem,performance,metrics,agent,observability
  10. Platform: Platform Independent
  11. Classifier: Development Status :: 5 - Production/Stable
  12. Classifier: Environment :: Console
  13. Classifier: Environment :: Win32 (MS Windows)
  14. Classifier: Intended Audience :: Developers
  15. Classifier: Intended Audience :: Information Technology
  16. Classifier: Intended Audience :: System Administrators
  17. Classifier: License :: OSI Approved :: BSD License
  18. Classifier: Operating System :: MacOS :: MacOS X
  19. Classifier: Operating System :: Microsoft :: Windows :: Windows 10
  20. Classifier: Operating System :: Microsoft :: Windows :: Windows 7
  21. Classifier: Operating System :: Microsoft :: Windows :: Windows 8
  22. Classifier: Operating System :: Microsoft :: Windows :: Windows 8.1
  23. Classifier: Operating System :: Microsoft :: Windows :: Windows Server 2003
  24. Classifier: Operating System :: Microsoft :: Windows :: Windows Server 2008
  25. Classifier: Operating System :: Microsoft :: Windows :: Windows Vista
  26. Classifier: Operating System :: Microsoft
  27. Classifier: Operating System :: OS Independent
  28. Classifier: Operating System :: POSIX :: AIX
  29. Classifier: Operating System :: POSIX :: BSD :: FreeBSD
  30. Classifier: Operating System :: POSIX :: BSD :: NetBSD
  31. Classifier: Operating System :: POSIX :: BSD :: OpenBSD
  32. Classifier: Operating System :: POSIX :: BSD
  33. Classifier: Operating System :: POSIX :: Linux
  34. Classifier: Operating System :: POSIX :: SunOS/Solaris
  35. Classifier: Operating System :: POSIX
  36. Classifier: Programming Language :: C
  37. Classifier: Programming Language :: Python :: 2
  38. Classifier: Programming Language :: Python :: 2.6
  39. Classifier: Programming Language :: Python :: 2.7
  40. Classifier: Programming Language :: Python :: 3
  41. Classifier: Programming Language :: Python :: Implementation :: CPython
  42. Classifier: Programming Language :: Python :: Implementation :: PyPy
  43. Classifier: Programming Language :: Python
  44. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  45. Classifier: Topic :: Software Development :: Libraries
  46. Classifier: Topic :: System :: Benchmark
  47. Classifier: Topic :: System :: Hardware :: Hardware Drivers
  48. Classifier: Topic :: System :: Hardware
  49. Classifier: Topic :: System :: Monitoring
  50. Classifier: Topic :: System :: Networking :: Monitoring :: Hardware Watchdog
  51. Classifier: Topic :: System :: Networking :: Monitoring
  52. Classifier: Topic :: System :: Networking
  53. Classifier: Topic :: System :: Operating System
  54. Classifier: Topic :: System :: Systems Administration
  55. Classifier: Topic :: Utilities
  56. Requires-Python: >=2.6, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
  57. Description-Content-Type: text/x-rst
  58. Provides-Extra: test
  59. Requires-Dist: ipaddress ; (python_version < "3.0") and extra == 'test'
  60. Requires-Dist: mock ; (python_version < "3.0") and extra == 'test'
  61. Requires-Dist: unittest2 ; (python_version < "3.0") and extra == 'test'
  62. Requires-Dist: enum34 ; (python_version <= "3.4") and extra == 'test'
  63. Requires-Dist: pywin32 ; (sys_platform == "win32") and extra == 'test'
  64. Requires-Dist: wmi ; (sys_platform == "win32") and extra == 'test'
  65. | |downloads| |stars| |forks| |contributors| |coverage| |quality|
  66. | |version| |py-versions| |packages| |license|
  67. | |travis| |appveyor| |cirrus| |doc| |twitter| |tidelift|
  68. .. |downloads| image:: https://img.shields.io/pypi/dm/psutil.svg
  69. :target: https://pepy.tech/project/psutil
  70. :alt: Downloads
  71. .. |stars| image:: https://img.shields.io/github/stars/giampaolo/psutil.svg
  72. :target: https://github.com/giampaolo/psutil/stargazers
  73. :alt: Github stars
  74. .. |forks| image:: https://img.shields.io/github/forks/giampaolo/psutil.svg
  75. :target: https://github.com/giampaolo/psutil/network/members
  76. :alt: Github forks
  77. .. |contributors| image:: https://img.shields.io/github/contributors/giampaolo/psutil.svg
  78. :target: https://github.com/giampaolo/psutil/graphs/contributors
  79. :alt: Contributors
  80. .. |quality| image:: https://img.shields.io/codacy/grade/ce63e7f7f69d44b5b59682196e6fbfca.svg
  81. :target: https://www.codacy.com/app/g-rodola/psutil?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=giampaolo/psutil&amp;utm_campaign=Badge_Grade
  82. :alt: Code quality
  83. .. |travis| image:: https://img.shields.io/travis/giampaolo/psutil/master.svg?maxAge=3600&label=Linux,%20OSX,%20PyPy
  84. :target: https://travis-ci.org/giampaolo/psutil
  85. :alt: Linux tests (Travis)
  86. .. |appveyor| image:: https://img.shields.io/appveyor/ci/giampaolo/psutil/master.svg?maxAge=3600&label=Windows
  87. :target: https://ci.appveyor.com/project/giampaolo/psutil
  88. :alt: Windows tests (Appveyor)
  89. .. |cirrus| image:: https://img.shields.io/cirrus/github/giampaolo/psutil?label=FreeBSD
  90. :target: https://cirrus-ci.com/github/giampaolo/psutil-cirrus-ci
  91. :alt: FreeBSD tests (Cirrus-Ci)
  92. .. |coverage| image:: https://coveralls.io/repos/github/giampaolo/psutil/badge.svg?branch=master
  93. :target: https://coveralls.io/github/giampaolo/psutil?branch=master
  94. :alt: Test coverage (coverall.io)
  95. .. |doc| image:: https://readthedocs.org/projects/psutil/badge/?version=latest
  96. :target: http://psutil.readthedocs.io/en/latest/?badge=latest
  97. :alt: Documentation Status
  98. .. |version| image:: https://img.shields.io/pypi/v/psutil.svg?label=pypi
  99. :target: https://pypi.org/project/psutil
  100. :alt: Latest version
  101. .. |py-versions| image:: https://img.shields.io/pypi/pyversions/psutil.svg
  102. :target: https://pypi.org/project/psutil
  103. :alt: Supported Python versions
  104. .. |packages| image:: https://repology.org/badge/tiny-repos/python:psutil.svg
  105. :target: https://repology.org/metapackage/python:psutil/versions
  106. :alt: Binary packages
  107. .. |license| image:: https://img.shields.io/pypi/l/psutil.svg
  108. :target: https://github.com/giampaolo/psutil/blob/master/LICENSE
  109. :alt: License
  110. .. |twitter| image:: https://img.shields.io/twitter/follow/grodola.svg?label=follow&style=flat&logo=twitter&logoColor=4FADFF
  111. :target: https://twitter.com/grodola
  112. :alt: Twitter Follow
  113. .. |tidelift| image:: https://tidelift.com/badges/github/giampaolo/psutil?style=flat
  114. :target: https://tidelift.com/subscription/pkg/pypi-psutil?utm_source=pypi-psutil&utm_medium=referral&utm_campaign=readme
  115. :alt: Tidelift
  116. -----
  117. Quick links
  118. ===========
  119. - `Home page <https://github.com/giampaolo/psutil>`_
  120. - `Install <https://github.com/giampaolo/psutil/blob/master/INSTALL.rst>`_
  121. - `Documentation <http://psutil.readthedocs.io>`_
  122. - `Download <https://pypi.org/project/psutil/#files>`_
  123. - `Forum <http://groups.google.com/group/psutil/topics>`_
  124. - `StackOverflow <https://stackoverflow.com/questions/tagged/psutil>`_
  125. - `Blog <https://gmpy.dev/tags/psutil>`_
  126. - `What's new <https://github.com/giampaolo/psutil/blob/master/HISTORY.rst>`_
  127. Summary
  128. =======
  129. psutil (process and system utilities) is a cross-platform library for
  130. retrieving information on **running processes** and **system utilization**
  131. (CPU, memory, disks, network, sensors) in Python.
  132. It is useful mainly for **system monitoring**, **profiling and limiting process
  133. resources** and **management of running processes**.
  134. It implements many functionalities offered by classic UNIX command line tools
  135. such as *ps, top, iotop, lsof, netstat, ifconfig, free* and others.
  136. psutil currently supports the following platforms:
  137. - **Linux**
  138. - **Windows**
  139. - **macOS**
  140. - **FreeBSD, OpenBSD**, **NetBSD**
  141. - **Sun Solaris**
  142. - **AIX**
  143. ...both **32-bit** and **64-bit** architectures. Supported Python versions are **2.6**, **2.7** and **3.4+**, `PyPy <http://pypy.org/>`__ 2.7 and 3.X.
  144. Funding
  145. =======
  146. While psutil is free software and will always be, the project would benefit
  147. immensely from some funding.
  148. Keeping up with bug reports and maintenance has become hardly sustainable for
  149. me alone in terms of time.
  150. If you're a company that's making significant use of psutil you can consider
  151. becoming a sponsor via `GitHub <https://github.com/sponsors/giampaolo>`__,
  152. `Open Collective <https://opencollective.com/psutil>`__ or
  153. `PayPal <https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A9ZS7PKKRM3S8>`__
  154. and have your logo displayed in here and psutil `doc <https://psutil.readthedocs.io>`__.
  155. Sponsors
  156. ========
  157. .. image:: https://github.com/giampaolo/psutil/raw/master/docs/_static/tidelift-logo.png
  158. :width: 200
  159. :alt: Alternative text
  160. `Add your logo <https://github.com/sponsors/giampaolo>`__.
  161. Example usages
  162. ==============
  163. This represents pretty much the whole psutil API.
  164. CPU
  165. ---
  166. .. code-block:: python
  167. >>> import psutil
  168. >>>
  169. >>> psutil.cpu_times()
  170. scputimes(user=3961.46, nice=169.729, system=2150.659, idle=16900.540, iowait=629.59, irq=0.0, softirq=19.42, steal=0.0, guest=0, nice=0.0)
  171. >>>
  172. >>> for x in range(3):
  173. ... psutil.cpu_percent(interval=1)
  174. ...
  175. 4.0
  176. 5.9
  177. 3.8
  178. >>>
  179. >>> for x in range(3):
  180. ... psutil.cpu_percent(interval=1, percpu=True)
  181. ...
  182. [4.0, 6.9, 3.7, 9.2]
  183. [7.0, 8.5, 2.4, 2.1]
  184. [1.2, 9.0, 9.9, 7.2]
  185. >>>
  186. >>> for x in range(3):
  187. ... psutil.cpu_times_percent(interval=1, percpu=False)
  188. ...
  189. scputimes(user=1.5, nice=0.0, system=0.5, idle=96.5, iowait=1.5, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
  190. scputimes(user=1.0, nice=0.0, system=0.0, idle=99.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
  191. scputimes(user=2.0, nice=0.0, system=0.0, idle=98.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
  192. >>>
  193. >>> psutil.cpu_count()
  194. 4
  195. >>> psutil.cpu_count(logical=False)
  196. 2
  197. >>>
  198. >>> psutil.cpu_stats()
  199. scpustats(ctx_switches=20455687, interrupts=6598984, soft_interrupts=2134212, syscalls=0)
  200. >>>
  201. >>> psutil.cpu_freq()
  202. scpufreq(current=931.42925, min=800.0, max=3500.0)
  203. >>>
  204. >>> psutil.getloadavg() # also on Windows (emulated)
  205. (3.14, 3.89, 4.67)
  206. Memory
  207. ------
  208. .. code-block:: python
  209. >>> psutil.virtual_memory()
  210. svmem(total=10367352832, available=6472179712, percent=37.6, used=8186245120, free=2181107712, active=4748992512, inactive=2758115328, buffers=790724608, cached=3500347392, shared=787554304)
  211. >>> psutil.swap_memory()
  212. sswap(total=2097147904, used=296128512, free=1801019392, percent=14.1, sin=304193536, sout=677842944)
  213. >>>
  214. Disks
  215. -----
  216. .. code-block:: python
  217. >>> psutil.disk_partitions()
  218. [sdiskpart(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid'),
  219. sdiskpart(device='/dev/sda2', mountpoint='/home', fstype='ext, opts='rw')]
  220. >>>
  221. >>> psutil.disk_usage('/')
  222. sdiskusage(total=21378641920, used=4809781248, free=15482871808, percent=22.5)
  223. >>>
  224. >>> psutil.disk_io_counters(perdisk=False)
  225. sdiskio(read_count=719566, write_count=1082197, read_bytes=18626220032, write_bytes=24081764352, read_time=5023392, write_time=63199568, read_merged_count=619166, write_merged_count=812396, busy_time=4523412)
  226. >>>
  227. Network
  228. -------
  229. .. code-block:: python
  230. >>> psutil.net_io_counters(pernic=True)
  231. {'eth0': netio(bytes_sent=485291293, bytes_recv=6004858642, packets_sent=3251564, packets_recv=4787798, errin=0, errout=0, dropin=0, dropout=0),
  232. 'lo': netio(bytes_sent=2838627, bytes_recv=2838627, packets_sent=30567, packets_recv=30567, errin=0, errout=0, dropin=0, dropout=0)}
  233. >>>
  234. >>> psutil.net_connections()
  235. [sconn(fd=115, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=48776), raddr=addr(ip='93.186.135.91', port=80), status='ESTABLISHED', pid=1254),
  236. sconn(fd=117, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=43761), raddr=addr(ip='72.14.234.100', port=80), status='CLOSING', pid=2987),
  237. ...]
  238. >>>
  239. >>> psutil.net_if_addrs()
  240. {'lo': [snicaddr(family=<AddressFamily.AF_INET: 2>, address='127.0.0.1', netmask='255.0.0.0', broadcast='127.0.0.1', ptp=None),
  241. snicaddr(family=<AddressFamily.AF_INET6: 10>, address='::1', netmask='ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', broadcast=None, ptp=None),
  242. snicaddr(family=<AddressFamily.AF_LINK: 17>, address='00:00:00:00:00:00', netmask=None, broadcast='00:00:00:00:00:00', ptp=None)],
  243. 'wlan0': [snicaddr(family=<AddressFamily.AF_INET: 2>, address='192.168.1.3', netmask='255.255.255.0', broadcast='192.168.1.255', ptp=None),
  244. snicaddr(family=<AddressFamily.AF_INET6: 10>, address='fe80::c685:8ff:fe45:641%wlan0', netmask='ffff:ffff:ffff:ffff::', broadcast=None, ptp=None),
  245. snicaddr(family=<AddressFamily.AF_LINK: 17>, address='c4:85:08:45:06:41', netmask=None, broadcast='ff:ff:ff:ff:ff:ff', ptp=None)]}
  246. >>>
  247. >>> psutil.net_if_stats()
  248. {'lo': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_UNKNOWN: 0>, speed=0, mtu=65536),
  249. 'wlan0': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_FULL: 2>, speed=100, mtu=1500)}
  250. >>>
  251. Sensors
  252. -------
  253. .. code-block:: python
  254. >>> import psutil
  255. >>> psutil.sensors_temperatures()
  256. {'acpitz': [shwtemp(label='', current=47.0, high=103.0, critical=103.0)],
  257. 'asus': [shwtemp(label='', current=47.0, high=None, critical=None)],
  258. 'coretemp': [shwtemp(label='Physical id 0', current=52.0, high=100.0, critical=100.0),
  259. shwtemp(label='Core 0', current=45.0, high=100.0, critical=100.0)]}
  260. >>>
  261. >>> psutil.sensors_fans()
  262. {'asus': [sfan(label='cpu_fan', current=3200)]}
  263. >>>
  264. >>> psutil.sensors_battery()
  265. sbattery(percent=93, secsleft=16628, power_plugged=False)
  266. >>>
  267. Other system info
  268. -----------------
  269. .. code-block:: python
  270. >>> import psutil
  271. >>> psutil.users()
  272. [suser(name='giampaolo', terminal='pts/2', host='localhost', started=1340737536.0, pid=1352),
  273. suser(name='giampaolo', terminal='pts/3', host='localhost', started=1340737792.0, pid=1788)]
  274. >>>
  275. >>> psutil.boot_time()
  276. 1365519115.0
  277. >>>
  278. Process management
  279. ------------------
  280. .. code-block:: python
  281. >>> import psutil
  282. >>> psutil.pids()
  283. [1, 2, 3, 4, 5, 6, 7, 46, 48, 50, 51, 178, 182, 222, 223, 224, 268, 1215, 1216, 1220, 1221, 1243, 1244,
  284. 1301, 1601, 2237, 2355, 2637, 2774, 3932, 4176, 4177, 4185, 4187, 4189, 4225, 4243, 4245, 4263, 4282,
  285. 4306, 4311, 4312, 4313, 4314, 4337, 4339, 4357, 4358, 4363, 4383, 4395, 4408, 4433, 4443, 4445, 4446,
  286. 5167, 5234, 5235, 5252, 5318, 5424, 5644, 6987, 7054, 7055, 7071]
  287. >>>
  288. >>> p = psutil.Process(7055)
  289. >>> p
  290. psutil.Process(pid=7055, name='python3', status='running', started='09:04:44')
  291. >>> p.name()
  292. 'python'
  293. >>> p.exe()
  294. '/usr/bin/python'
  295. >>> p.cwd()
  296. '/home/giampaolo'
  297. >>> p.cmdline()
  298. ['/usr/bin/python', 'main.py']
  299. >>>
  300. >>> p.pid
  301. 7055
  302. >>> p.ppid()
  303. 7054
  304. >>> p.children(recursive=True)
  305. [psutil.Process(pid=29835, name='python3', status='sleeping', started='11:45:38'),
  306. psutil.Process(pid=29836, name='python3', status='waking', started='11:43:39')]
  307. >>>
  308. >>> p.parent()
  309. psutil.Process(pid=4699, name='bash', status='sleeping', started='09:06:44')
  310. >>> p.parents()
  311. [psutil.Process(pid=4699, name='bash', started='09:06:44'),
  312. psutil.Process(pid=4689, name='gnome-terminal-server', status='sleeping', started='0:06:44'),
  313. psutil.Process(pid=1, name='systemd', status='sleeping', started='05:56:55')]
  314. >>>
  315. >>> p.status()
  316. 'running'
  317. >>> p.username()
  318. 'giampaolo'
  319. >>> p.create_time()
  320. 1267551141.5019531
  321. >>> p.terminal()
  322. '/dev/pts/0'
  323. >>>
  324. >>> p.uids()
  325. puids(real=1000, effective=1000, saved=1000)
  326. >>> p.gids()
  327. pgids(real=1000, effective=1000, saved=1000)
  328. >>>
  329. >>> p.cpu_times()
  330. pcputimes(user=1.02, system=0.31, children_user=0.32, children_system=0.1, iowait=0.0)
  331. >>> p.cpu_percent(interval=1.0)
  332. 12.1
  333. >>> p.cpu_affinity()
  334. [0, 1, 2, 3]
  335. >>> p.cpu_affinity([0, 1]) # set
  336. >>> p.cpu_num()
  337. 1
  338. >>>
  339. >>> p.memory_info()
  340. pmem(rss=10915840, vms=67608576, shared=3313664, text=2310144, lib=0, data=7262208, dirty=0)
  341. >>> p.memory_full_info() # "real" USS memory usage (Linux, macOS, Win only)
  342. pfullmem(rss=10199040, vms=52133888, shared=3887104, text=2867200, lib=0, data=5967872, dirty=0, uss=6545408, pss=6872064, swap=0)
  343. >>> p.memory_percent()
  344. 0.7823
  345. >>> p.memory_maps()
  346. [pmmap_grouped(path='/lib/x8664-linux-gnu/libutil-2.15.so', rss=32768, size=2125824, pss=32768, shared_clean=0, shared_dirty=0, private_clean=20480, private_dirty=12288, referenced=32768, anonymous=12288, swap=0),
  347. pmmap_grouped(path='/lib/x8664-linux-gnu/libc-2.15.so', rss=3821568, size=3842048, pss=3821568, shared_clean=0, shared_dirty=0, private_clean=0, private_dirty=3821568, referenced=3575808, anonymous=3821568, swap=0),
  348. pmmap_grouped(path='[heap]', rss=32768, size=139264, pss=32768, shared_clean=0, shared_dirty=0, private_clean=0, private_dirty=32768, referenced=32768, anonymous=32768, swap=0),
  349. pmmap_grouped(path='[stack]', rss=2465792, size=2494464, pss=2465792, shared_clean=0, shared_dirty=0, private_clean=0, private_dirty=2465792, referenced=2277376, anonymous=2465792, swap=0),
  350. ...]
  351. >>>
  352. >>> p.io_counters()
  353. pio(read_count=478001, write_count=59371, read_bytes=700416, write_bytes=69632, read_chars=456232, write_chars=517543)
  354. >>>
  355. >>> p.open_files()
  356. [popenfile(path='/home/giampaolo/monit.py', fd=3, position=0, mode='r', flags=32768),
  357. popenfile(path='/var/log/monit.log', fd=4, position=235542, mode='a', flags=33793)]
  358. >>>
  359. >>> p.connections()
  360. [pconn(fd=115, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=48776), raddr=addr(ip='93.186.135.91', port=80), status='ESTABLISHED'),
  361. pconn(fd=117, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=43761), raddr=addr(ip='72.14.234.100', port=80), status='CLOSING')]
  362. >>>
  363. >>> p.num_threads()
  364. 4
  365. >>> p.num_fds()
  366. 8
  367. >>> p.threads()
  368. [pthread(id=5234, user_time=22.5, system_time=9.2891),
  369. pthread(id=5237, user_time=0.0707, system_time=1.1)]
  370. >>>
  371. >>> p.num_ctx_switches()
  372. pctxsw(voluntary=78, involuntary=19)
  373. >>>
  374. >>> p.nice()
  375. 0
  376. >>> p.nice(10) # set
  377. >>>
  378. >>> p.ionice(psutil.IOPRIO_CLASS_IDLE) # IO priority (Win and Linux only)
  379. >>> p.ionice()
  380. pionice(ioclass=<IOPriority.IOPRIO_CLASS_IDLE: 3>, value=0)
  381. >>>
  382. >>> p.rlimit(psutil.RLIMIT_NOFILE, (5, 5)) # set resource limits (Linux only)
  383. >>> p.rlimit(psutil.RLIMIT_NOFILE)
  384. (5, 5)
  385. >>>
  386. >>> p.environ()
  387. {'LC_PAPER': 'it_IT.UTF-8', 'SHELL': '/bin/bash', 'GREP_OPTIONS': '--color=auto',
  388. 'XDG_CONFIG_DIRS': '/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg',
  389. ...}
  390. >>>
  391. >>> p.as_dict()
  392. {'status': 'running', 'num_ctx_switches': pctxsw(voluntary=63, involuntary=1), 'pid': 5457, ...}
  393. >>> p.is_running()
  394. True
  395. >>> p.suspend()
  396. >>> p.resume()
  397. >>>
  398. >>> p.terminate()
  399. >>> p.kill()
  400. >>> p.wait(timeout=3)
  401. <Exitcode.EX_OK: 0>
  402. >>>
  403. >>> psutil.test()
  404. USER PID %CPU %MEM VSZ RSS TTY START TIME COMMAND
  405. root 1 0.0 0.0 24584 2240 Jun17 00:00 init
  406. root 2 0.0 0.0 0 0 Jun17 00:00 kthreadd
  407. ...
  408. giampaolo 31475 0.0 0.0 20760 3024 /dev/pts/0 Jun19 00:00 python2.4
  409. giampaolo 31721 0.0 2.2 773060 181896 00:04 10:30 chrome
  410. root 31763 0.0 0.0 0 0 00:05 00:00 kworker/0:1
  411. >>>
  412. Further process APIs
  413. --------------------
  414. .. code-block:: python
  415. >>> import psutil
  416. >>> for proc in psutil.process_iter(['pid', 'name']):
  417. ... print(proc.info)
  418. ...
  419. {'pid': 1, 'name': 'systemd'}
  420. {'pid': 2, 'name': 'kthreadd'}
  421. {'pid': 3, 'name': 'ksoftirqd/0'}
  422. ...
  423. >>>
  424. >>> psutil.pid_exists(3)
  425. True
  426. >>>
  427. >>> def on_terminate(proc):
  428. ... print("process {} terminated".format(proc))
  429. ...
  430. >>> # waits for multiple processes to terminate
  431. >>> gone, alive = psutil.wait_procs(procs_list, timeout=3, callback=on_terminate)
  432. >>>
  433. Popen wrapper:
  434. .. code-block:: python
  435. >>> import psutil
  436. >>> from subprocess import PIPE
  437. >>> p = psutil.Popen(["/usr/bin/python", "-c", "print('hello')"], stdout=PIPE)
  438. >>> p.name()
  439. 'python'
  440. >>> p.username()
  441. 'giampaolo'
  442. >>> p.communicate()
  443. ('hello\n', None)
  444. >>> p.wait(timeout=2)
  445. 0
  446. >>>
  447. Windows services
  448. ----------------
  449. .. code-block:: python
  450. >>> list(psutil.win_service_iter())
  451. [<WindowsService(name='AeLookupSvc', display_name='Application Experience') at 38850096>,
  452. <WindowsService(name='ALG', display_name='Application Layer Gateway Service') at 38850128>,
  453. <WindowsService(name='APNMCP', display_name='Ask Update Service') at 38850160>,
  454. <WindowsService(name='AppIDSvc', display_name='Application Identity') at 38850192>,
  455. ...]
  456. >>> s = psutil.win_service_get('alg')
  457. >>> s.as_dict()
  458. {'binpath': 'C:\\Windows\\System32\\alg.exe',
  459. 'description': 'Provides support for 3rd party protocol plug-ins for Internet Connection Sharing',
  460. 'display_name': 'Application Layer Gateway Service',
  461. 'name': 'alg',
  462. 'pid': None,
  463. 'start_type': 'manual',
  464. 'status': 'stopped',
  465. 'username': 'NT AUTHORITY\\LocalService'}
  466. Projects using psutil
  467. =====================
  468. Here's some I find particularly interesting:
  469. - https://github.com/google/grr
  470. - https://github.com/facebook/osquery/
  471. - https://github.com/nicolargo/glances
  472. - https://github.com/Jahaja/psdash
  473. - https://github.com/ajenti/ajenti
  474. - https://github.com/home-assistant/home-assistant/
  475. Portings
  476. ========
  477. - Go: https://github.com/shirou/gopsutil
  478. - C: https://github.com/hamon-in/cpslib
  479. - Rust: https://github.com/rust-psutil/rust-psutil
  480. - Nim: https://github.com/johnscillieri/psutil-nim
  481. Security
  482. ========
  483. To report a security vulnerability, please use the `Tidelift security
  484. contact`_. Tidelift will coordinate the fix and disclosure.
  485. .. _`Giampaolo Rodola`: https://gmpy.dev/about
  486. .. _`donation`: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A9ZS7PKKRM3S8
  487. .. _Tidelift security contact: https://tidelift.com/security
  488. .. _Tidelift Subscription: https://tidelift.com/subscription/pkg/pypi-psutil?utm_source=pypi-psutil&utm_medium=referral&utm_campaign=readme