1.1.2 System Process Management method

Source: Internet
Author: User

#!/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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.