You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

528 lines
22 KiB

4 years ago
  1. Metadata-Version: 2.1
  2. Name: psutil
  3. Version: 5.4.8
  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 NT/2000
  20. Classifier: Operating System :: Microsoft
  21. Classifier: Operating System :: OS Independent
  22. Classifier: Operating System :: POSIX :: BSD :: FreeBSD
  23. Classifier: Operating System :: POSIX :: BSD :: NetBSD
  24. Classifier: Operating System :: POSIX :: BSD :: OpenBSD
  25. Classifier: Operating System :: POSIX :: BSD
  26. Classifier: Operating System :: POSIX :: Linux
  27. Classifier: Operating System :: POSIX :: SunOS/Solaris
  28. Classifier: Operating System :: POSIX
  29. Classifier: Programming Language :: C
  30. Classifier: Programming Language :: Python :: 2
  31. Classifier: Programming Language :: Python :: 2.6
  32. Classifier: Programming Language :: Python :: 2.7
  33. Classifier: Programming Language :: Python :: 3
  34. Classifier: Programming Language :: Python :: 3.4
  35. Classifier: Programming Language :: Python :: 3.5
  36. Classifier: Programming Language :: Python :: 3.6
  37. Classifier: Programming Language :: Python :: 3.7
  38. Classifier: Programming Language :: Python :: Implementation :: CPython
  39. Classifier: Programming Language :: Python :: Implementation :: PyPy
  40. Classifier: Programming Language :: Python
  41. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  42. Classifier: Topic :: Software Development :: Libraries
  43. Classifier: Topic :: System :: Benchmark
  44. Classifier: Topic :: System :: Hardware
  45. Classifier: Topic :: System :: Monitoring
  46. Classifier: Topic :: System :: Networking :: Monitoring
  47. Classifier: Topic :: System :: Networking
  48. Classifier: Topic :: System :: Operating System
  49. Classifier: Topic :: System :: Systems Administration
  50. Classifier: Topic :: Utilities
  51. Requires-Python: >=2.6, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
  52. .. image:: http://pepy.tech/badge/psutil
  53. :target: http://pepy.tech/project/psutil
  54. :alt: Downloads
  55. .. image:: https://img.shields.io/travis/giampaolo/psutil/master.svg?maxAge=3600&label=Linux%20/%20macOS
  56. :target: https://travis-ci.org/giampaolo/psutil
  57. :alt: Linux tests (Travis)
  58. .. image:: https://img.shields.io/appveyor/ci/giampaolo/psutil/master.svg?maxAge=3600&label=Windows
  59. :target: https://ci.appveyor.com/project/giampaolo/psutil
  60. :alt: Windows tests (Appveyor)
  61. .. image:: https://coveralls.io/repos/github/giampaolo/psutil/badge.svg?branch=master
  62. :target: https://coveralls.io/github/giampaolo/psutil?branch=master
  63. :alt: Test coverage (coverall.io)
  64. .. image:: https://readthedocs.org/projects/psutil/badge/?version=latest
  65. :target: http://psutil.readthedocs.io/en/latest/?badge=latest
  66. :alt: Documentation Status
  67. .. image:: https://img.shields.io/pypi/v/psutil.svg?label=pypi
  68. :target: https://pypi.org/project/psutil
  69. :alt: Latest version
  70. .. image:: https://img.shields.io/github/stars/giampaolo/psutil.svg
  71. :target: https://github.com/giampaolo/psutil/
  72. :alt: Github stars
  73. .. image:: https://img.shields.io/pypi/l/psutil.svg
  74. :target: https://pypi.org/project/psutil
  75. :alt: License
  76. ===========
  77. Quick links
  78. ===========
  79. - `Home page <https://github.com/giampaolo/psutil>`_
  80. - `Install <https://github.com/giampaolo/psutil/blob/master/INSTALL.rst>`_
  81. - `Documentation <http://psutil.readthedocs.io>`_
  82. - `Download <https://pypi.org/project/psutil/#files>`_
  83. - `Forum <http://groups.google.com/group/psutil/topics>`_
  84. - `StackOverflow <https://stackoverflow.com/questions/tagged/psutil>`_
  85. - `Blog <http://grodola.blogspot.com/search/label/psutil>`_
  86. - `Development guide <https://github.com/giampaolo/psutil/blob/master/DEVGUIDE.rst>`_
  87. - `What's new <https://github.com/giampaolo/psutil/blob/master/HISTORY.rst>`_
  88. =======
  89. Summary
  90. =======
  91. psutil (process and system utilities) is a cross-platform library for
  92. retrieving information on **running processes** and **system utilization**
  93. (CPU, memory, disks, network, sensors) in Python.
  94. It is useful mainly for **system monitoring**, **profiling and limiting process
  95. resources** and **management of running processes**.
  96. It implements many functionalities offered by UNIX command line tools such as:
  97. ps, top, lsof, netstat, ifconfig, who, df, kill, free, nice, ionice, iostat,
  98. iotop, uptime, pidof, tty, taskset, pmap.
  99. psutil currently supports the following platforms:
  100. - **Linux**
  101. - **Windows**
  102. - **macOS**,
  103. - **FreeBSD, OpenBSD**, **NetBSD**
  104. - **Sun Solaris**
  105. - **AIX**
  106. ...both **32-bit** and **64-bit** architectures, with Python versions **2.6,
  107. 2.7, and 3.4+**. `PyPy <http://pypy.org/>`__ is also known to work.
  108. ====================
  109. Example applications
  110. ====================
  111. +------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------+
  112. | .. image:: https://github.com/giampaolo/psutil/blob/master/docs/_static/procinfo-small.png | .. image:: https://github.com/giampaolo/psutil/blob/master/docs/_static/top-small.png |
  113. | :target: https://github.com/giampaolo/psutil/blob/master/docs/_static/procinfo.png | :target: https://github.com/giampaolo/psutil/blob/master/docs/_static/top.png |
  114. +------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------+
  115. | .. image:: https://github.com/giampaolo/psutil/blob/master/docs/_static/procsmem-small.png | .. image:: https://github.com/giampaolo/psutil/blob/master/docs/_static/pmap-small.png |
  116. | :target: https://github.com/giampaolo/psutil/blob/master/docs/_static/procsmem.png | :target: https://github.com/giampaolo/psutil/blob/master/docs/_static/pmap.png |
  117. +------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------+
  118. Also see `scripts directory <https://github.com/giampaolo/psutil/tree/master/scripts>`__
  119. and `doc recipes <http://psutil.readthedocs.io/#recipes/>`__.
  120. =====================
  121. Projects using psutil
  122. =====================
  123. At the time of writing psutil has roughly
  124. `2.9 milion downloads <https://github.com/giampaolo/psutil/issues/1053#issuecomment-340166262>`__
  125. per month and there are over
  126. `8000 open source projects <https://libraries.io/pypi/psutil/dependent_repositories?page=1>`__
  127. on github which depend from psutil.
  128. Here's some I find particularly interesting:
  129. - https://github.com/facebook/osquery/
  130. - https://github.com/nicolargo/glances
  131. - https://github.com/google/grr
  132. - https://github.com/Jahaja/psdash
  133. - https://github.com/ajenti/ajenti
  134. - https://github.com/home-assistant/home-assistant/
  135. ========
  136. Portings
  137. ========
  138. - Go: https://github.com/shirou/gopsutil
  139. - C: https://github.com/hamon-in/cpslib
  140. - Node: https://github.com/christkv/node-psutil
  141. - Rust: https://github.com/borntyping/rust-psutil
  142. - Ruby: https://github.com/spacewander/posixpsutil
  143. - Nim: https://github.com/johnscillieri/psutil-nim
  144. ==============
  145. Example usages
  146. ==============
  147. CPU
  148. ===
  149. .. code-block:: python
  150. >>> import psutil
  151. >>> psutil.cpu_times()
  152. 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)
  153. >>>
  154. >>> for x in range(3):
  155. ... psutil.cpu_percent(interval=1)
  156. ...
  157. 4.0
  158. 5.9
  159. 3.8
  160. >>>
  161. >>> for x in range(3):
  162. ... psutil.cpu_percent(interval=1, percpu=True)
  163. ...
  164. [4.0, 6.9, 3.7, 9.2]
  165. [7.0, 8.5, 2.4, 2.1]
  166. [1.2, 9.0, 9.9, 7.2]
  167. >>>
  168. >>> for x in range(3):
  169. ... psutil.cpu_times_percent(interval=1, percpu=False)
  170. ...
  171. 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)
  172. 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)
  173. 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)
  174. >>>
  175. >>> psutil.cpu_count()
  176. 4
  177. >>> psutil.cpu_count(logical=False)
  178. 2
  179. >>>
  180. >>> psutil.cpu_stats()
  181. scpustats(ctx_switches=20455687, interrupts=6598984, soft_interrupts=2134212, syscalls=0)
  182. >>>
  183. >>> psutil.cpu_freq()
  184. scpufreq(current=931.42925, min=800.0, max=3500.0)
  185. >>>
  186. Memory
  187. ======
  188. .. code-block:: python
  189. >>> import psutil
  190. >>> psutil.virtual_memory()
  191. svmem(total=10367352832, available=6472179712, percent=37.6, used=8186245120, free=2181107712, active=4748992512, inactive=2758115328, buffers=790724608, cached=3500347392, shared=787554304)
  192. >>> psutil.swap_memory()
  193. sswap(total=2097147904, used=296128512, free=1801019392, percent=14.1, sin=304193536, sout=677842944)
  194. >>>
  195. Disks
  196. =====
  197. .. code-block:: python
  198. >>> import psutil
  199. >>> psutil.disk_partitions()
  200. [sdiskpart(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid'),
  201. sdiskpart(device='/dev/sda2', mountpoint='/home', fstype='ext, opts='rw')]
  202. >>>
  203. >>> psutil.disk_usage('/')
  204. sdiskusage(total=21378641920, used=4809781248, free=15482871808, percent=22.5)
  205. >>>
  206. >>> psutil.disk_io_counters(perdisk=False)
  207. 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)
  208. >>>
  209. Network
  210. =======
  211. .. code-block:: python
  212. >>> import psutil
  213. >>> psutil.net_io_counters(pernic=True)
  214. {'eth0': netio(bytes_sent=485291293, bytes_recv=6004858642, packets_sent=3251564, packets_recv=4787798, errin=0, errout=0, dropin=0, dropout=0),
  215. 'lo': netio(bytes_sent=2838627, bytes_recv=2838627, packets_sent=30567, packets_recv=30567, errin=0, errout=0, dropin=0, dropout=0)}
  216. >>>
  217. >>> psutil.net_connections()
  218. [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),
  219. 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),
  220. sconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=60759), raddr=addr(ip='72.14.234.104', port=80), status='ESTABLISHED', pid=None),
  221. sconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=51314), raddr=addr(ip='72.14.234.83', port=443), status='SYN_SENT', pid=None)
  222. ...]
  223. >>>
  224. >>> psutil.net_if_addrs()
  225. {'lo': [snicaddr(family=<AddressFamily.AF_INET: 2>, address='127.0.0.1', netmask='255.0.0.0', broadcast='127.0.0.1', ptp=None),
  226. snicaddr(family=<AddressFamily.AF_INET6: 10>, address='::1', netmask='ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', broadcast=None, ptp=None),
  227. snicaddr(family=<AddressFamily.AF_LINK: 17>, address='00:00:00:00:00:00', netmask=None, broadcast='00:00:00:00:00:00', ptp=None)],
  228. 'wlan0': [snicaddr(family=<AddressFamily.AF_INET: 2>, address='192.168.1.3', netmask='255.255.255.0', broadcast='192.168.1.255', ptp=None),
  229. snicaddr(family=<AddressFamily.AF_INET6: 10>, address='fe80::c685:8ff:fe45:641%wlan0', netmask='ffff:ffff:ffff:ffff::', broadcast=None, ptp=None),
  230. snicaddr(family=<AddressFamily.AF_LINK: 17>, address='c4:85:08:45:06:41', netmask=None, broadcast='ff:ff:ff:ff:ff:ff', ptp=None)]}
  231. >>>
  232. >>> psutil.net_if_stats()
  233. {'eth0': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_FULL: 2>, speed=100, mtu=1500),
  234. 'lo': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_UNKNOWN: 0>, speed=0, mtu=65536)}
  235. >>>
  236. Sensors
  237. =======
  238. .. code-block:: python
  239. >>> import psutil
  240. >>> psutil.sensors_temperatures()
  241. {'acpitz': [shwtemp(label='', current=47.0, high=103.0, critical=103.0)],
  242. 'asus': [shwtemp(label='', current=47.0, high=None, critical=None)],
  243. 'coretemp': [shwtemp(label='Physical id 0', current=52.0, high=100.0, critical=100.0),
  244. shwtemp(label='Core 0', current=45.0, high=100.0, critical=100.0),
  245. shwtemp(label='Core 1', current=52.0, high=100.0, critical=100.0),
  246. shwtemp(label='Core 2', current=45.0, high=100.0, critical=100.0),
  247. shwtemp(label='Core 3', current=47.0, high=100.0, critical=100.0)]}
  248. >>>
  249. >>> psutil.sensors_fans()
  250. {'asus': [sfan(label='cpu_fan', current=3200)]}
  251. >>>
  252. >>> psutil.sensors_battery()
  253. sbattery(percent=93, secsleft=16628, power_plugged=False)
  254. >>>
  255. Other system info
  256. =================
  257. .. code-block:: python
  258. >>> import psutil
  259. >>> psutil.users()
  260. [suser(name='giampaolo', terminal='pts/2', host='localhost', started=1340737536.0, pid=1352),
  261. suser(name='giampaolo', terminal='pts/3', host='localhost', started=1340737792.0, pid=1788)]
  262. >>>
  263. >>> psutil.boot_time()
  264. 1365519115.0
  265. >>>
  266. Process management
  267. ==================
  268. .. code-block:: python
  269. >>> import psutil
  270. >>> psutil.pids()
  271. [1, 2, 3, 4, 5, 6, 7, 46, 48, 50, 51, 178, 182, 222, 223, 224, 268, 1215, 1216, 1220, 1221, 1243, 1244,
  272. 1301, 1601, 2237, 2355, 2637, 2774, 3932, 4176, 4177, 4185, 4187, 4189, 4225, 4243, 4245, 4263, 4282,
  273. 4306, 4311, 4312, 4313, 4314, 4337, 4339, 4357, 4358, 4363, 4383, 4395, 4408, 4433, 4443, 4445, 4446,
  274. 5167, 5234, 5235, 5252, 5318, 5424, 5644, 6987, 7054, 7055, 7071]
  275. >>>
  276. >>> p = psutil.Process(7055)
  277. >>> p.name()
  278. 'python'
  279. >>> p.exe()
  280. '/usr/bin/python'
  281. >>> p.cwd()
  282. '/home/giampaolo'
  283. >>> p.cmdline()
  284. ['/usr/bin/python', 'main.py']
  285. >>>
  286. >>> p.pid
  287. 7055
  288. >>> p.ppid()
  289. 7054
  290. >>> p.parent()
  291. <psutil.Process(pid=7054, name='bash') at 140008329539408>
  292. >>> p.children()
  293. [<psutil.Process(pid=8031, name='python') at 14020832451977>,
  294. <psutil.Process(pid=8044, name='python') at 19229444921932>]
  295. >>>
  296. >>> p.status()
  297. 'running'
  298. >>> p.username()
  299. 'giampaolo'
  300. >>> p.create_time()
  301. 1267551141.5019531
  302. >>> p.terminal()
  303. '/dev/pts/0'
  304. >>>
  305. >>> p.uids()
  306. puids(real=1000, effective=1000, saved=1000)
  307. >>> p.gids()
  308. pgids(real=1000, effective=1000, saved=1000)
  309. >>>
  310. >>> p.cpu_times()
  311. pcputimes(user=1.02, system=0.31, children_user=0.32, children_system=0.1)
  312. >>> p.cpu_percent(interval=1.0)
  313. 12.1
  314. >>> p.cpu_affinity()
  315. [0, 1, 2, 3]
  316. >>> p.cpu_affinity([0, 1]) # set
  317. >>> p.cpu_num()
  318. 1
  319. >>>
  320. >>> p.memory_info()
  321. pmem(rss=10915840, vms=67608576, shared=3313664, text=2310144, lib=0, data=7262208, dirty=0)
  322. >>> p.memory_full_info() # "real" USS memory usage (Linux, macOS, Win only)
  323. pfullmem(rss=10199040, vms=52133888, shared=3887104, text=2867200, lib=0, data=5967872, dirty=0, uss=6545408, pss=6872064, swap=0)
  324. >>> p.memory_percent()
  325. 0.7823
  326. >>> p.memory_maps()
  327. [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),
  328. 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),
  329. pmmap_grouped(path='/lib/x8664-linux-gnu/libcrypto.so.0.1', rss=34124, rss=32768, size=2134016, pss=15360, shared_clean=24576, shared_dirty=0, private_clean=0, private_dirty=8192, referenced=24576, anonymous=8192, swap=0),
  330. 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),
  331. 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),
  332. ...]
  333. >>>
  334. >>> p.io_counters()
  335. pio(read_count=478001, write_count=59371, read_bytes=700416, write_bytes=69632, read_chars=456232, write_chars=517543)
  336. >>>
  337. >>> p.open_files()
  338. [popenfile(path='/home/giampaolo/svn/psutil/setup.py', fd=3, position=0, mode='r', flags=32768),
  339. popenfile(path='/var/log/monitd', fd=4, position=235542, mode='a', flags=33793)]
  340. >>>
  341. >>> p.connections()
  342. [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'),
  343. 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'),
  344. pconn(fd=119, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=60759), raddr=addr(ip='72.14.234.104', port=80), status='ESTABLISHED'),
  345. pconn(fd=123, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=addr(ip='10.0.0.1', port=51314), raddr=addr(ip='72.14.234.83', port=443), status='SYN_SENT')]
  346. >>>
  347. >>> p.num_threads()
  348. 4
  349. >>> p.num_fds()
  350. 8
  351. >>> p.threads()
  352. [pthread(id=5234, user_time=22.5, system_time=9.2891),
  353. pthread(id=5235, user_time=0.0, system_time=0.0),
  354. pthread(id=5236, user_time=0.0, system_time=0.0),
  355. pthread(id=5237, user_time=0.0707, system_time=1.1)]
  356. >>>
  357. >>> p.num_ctx_switches()
  358. pctxsw(voluntary=78, involuntary=19)
  359. >>>
  360. >>> p.nice()
  361. 0
  362. >>> p.nice(10) # set
  363. >>>
  364. >>> p.ionice(psutil.IOPRIO_CLASS_IDLE) # IO priority (Win and Linux only)
  365. >>> p.ionice()
  366. pionice(ioclass=<IOPriority.IOPRIO_CLASS_IDLE: 3>, value=0)
  367. >>>
  368. >>> p.rlimit(psutil.RLIMIT_NOFILE, (5, 5)) # set resource limits (Linux only)
  369. >>> p.rlimit(psutil.RLIMIT_NOFILE)
  370. (5, 5)
  371. >>>
  372. >>> p.environ()
  373. {'LC_PAPER': 'it_IT.UTF-8', 'SHELL': '/bin/bash', 'GREP_OPTIONS': '--color=auto',
  374. 'XDG_CONFIG_DIRS': '/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg', 'COLORTERM': 'gnome-terminal',
  375. ...}
  376. >>>
  377. >>> p.as_dict()
  378. {'status': 'running', 'num_ctx_switches': pctxsw(voluntary=63, involuntary=1), 'pid': 5457, ...}
  379. >>> p.is_running()
  380. True
  381. >>> p.suspend()
  382. >>> p.resume()
  383. >>>
  384. >>> p.terminate()
  385. >>> p.wait(timeout=3)
  386. 0
  387. >>>
  388. >>> psutil.test()
  389. USER PID %CPU %MEM VSZ RSS TTY START TIME COMMAND
  390. root 1 0.0 0.0 24584 2240 Jun17 00:00 init
  391. root 2 0.0 0.0 0 0 Jun17 00:00 kthreadd
  392. root 3 0.0 0.0 0 0 Jun17 00:05 ksoftirqd/0
  393. ...
  394. giampaolo 31475 0.0 0.0 20760 3024 /dev/pts/0 Jun19 00:00 python2.4
  395. giampaolo 31721 0.0 2.2 773060 181896 00:04 10:30 chrome
  396. root 31763 0.0 0.0 0 0 00:05 00:00 kworker/0:1
  397. >>>
  398. Further process APIs
  399. ====================
  400. .. code-block:: python
  401. >>> import psutil
  402. >>> for proc in psutil.process_iter(attrs=['pid', 'name']):
  403. ... print(proc.info)
  404. ...
  405. {'pid': 1, 'name': 'systemd'}
  406. {'pid': 2, 'name': 'kthreadd'}
  407. {'pid': 3, 'name': 'ksoftirqd/0'}
  408. ...
  409. >>>
  410. >>> psutil.pid_exists(3)
  411. True
  412. >>>
  413. >>> def on_terminate(proc):
  414. ... print("process {} terminated".format(proc))
  415. ...
  416. >>> # waits for multiple processes to terminate
  417. >>> gone, alive = psutil.wait_procs(procs_list, timeout=3, callback=on_terminate)
  418. >>>
  419. Popen wrapper:
  420. .. code-block:: python
  421. >>> import psutil
  422. >>> from subprocess import PIPE
  423. >>> p = psutil.Popen(["/usr/bin/python", "-c", "print('hello')"], stdout=PIPE)
  424. >>> p.name()
  425. 'python'
  426. >>> p.username()
  427. 'giampaolo'
  428. >>> p.communicate()
  429. ('hello\n', None)
  430. >>> p.wait(timeout=2)
  431. 0
  432. >>>
  433. Windows services
  434. ================
  435. .. code-block:: python
  436. >>> list(psutil.win_service_iter())
  437. [<WindowsService(name='AeLookupSvc', display_name='Application Experience') at 38850096>,
  438. <WindowsService(name='ALG', display_name='Application Layer Gateway Service') at 38850128>,
  439. <WindowsService(name='APNMCP', display_name='Ask Update Service') at 38850160>,
  440. <WindowsService(name='AppIDSvc', display_name='Application Identity') at 38850192>,
  441. ...]
  442. >>> s = psutil.win_service_get('alg')
  443. >>> s.as_dict()
  444. {'binpath': 'C:\\Windows\\System32\\alg.exe',
  445. 'description': 'Provides support for 3rd party protocol plug-ins for Internet Connection Sharing',
  446. 'display_name': 'Application Layer Gateway Service',
  447. 'name': 'alg',
  448. 'pid': None,
  449. 'start_type': 'manual',
  450. 'status': 'stopped',
  451. 'username': 'NT AUTHORITY\\LocalService'}
  452. Other samples
  453. =============
  454. See `doc recipes <http://psutil.readthedocs.io/#recipes>`__.
  455. ======
  456. Author
  457. ======
  458. psutil was created and is maintained by
  459. `Giampaolo Rodola' <http://grodola.blogspot.com/p/about.html>`__.
  460. A lot of time and effort went into making psutil as it is right now.
  461. If you feel psutil is useful to you or your business and want to support its
  462. future development please consider donating me
  463. (`Giampaolo <http://grodola.blogspot.com/p/about.html>`__) some money.
  464. .. image:: http://www.paypal.com/en_US/i/btn/x-click-but04.gif
  465. :target: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A9ZS7PKKRM3S8
  466. :alt: Donate via PayPal
  467. Don't want to donate money? Then maybe you could `write me a recommendation on Linkedin <https://www.linkedin.com/in/grodola>`_.