#!/use/bin/python
#-*-Coution:utf-8-*-
#psutil is a cross-platform library that makes it easy to get the process and utilization of system running
Import Psutil
#1.1.2 System Process Management methods
‘‘‘
Get system process information and learn about the running state of the application
* Process Start time
*CPU Affinity Degree
* Memory Utilization
*io Information
*socket Connection
* Number of threads
‘‘‘
# (1) Process information
#列出所有进程PID
Print (Psutil.pids ())
#实例化一个process对象, the parameter is process PID
p = psutil. Process (2539)
Print (' Process name ', P.name ())
Print (' Process bin path ', P.exe ())
Print (' Process working directory absolute path ', P.CWD ())
Print (' Process status ', P.status ())
Print (' Process creation time ', P.create_time ())
Print (' Process UID information ', P.uids ())
Print (' Process GID info ', p.gids ())
Print (' Process CPU time information, including User,system two CPU time ', P.cpu_times ())
Print (' getcpu affinity, if you want to set CPU affinity, take the CPU as a contest ', p.cpu_affinity ())
Print (' Process memory utilization ', p.memory_percent ())
Print (' Process memory Rss,vms info ', P.memory_info ())
Print (' Process IO information, including read/write IO number and bytes ', p.io_counters ())
Print (' Returns the Namedutples list of open process sockets, including FS,FAMILY,LADDR, etc. ', p.connections ())
#popen类的使用
‘‘‘
The purpose of the Popen class provided by Psutil is to get user-initiated application process information so that it can track the running state of the process.
‘‘‘
Form subprocess Import PIPE
#通过psutil的Popen方法启动的应用程序, you can keep track of all relevant information that the program is running
p = psutil. Popen (["/usr/bin/python", "-C", "Print (' Hello ')"],stdout=pipe)
P.name ()
P.username ()
1.1.2 System Process Management method