Python process information

Source: Internet
Author: User

Read machine process information via Psutil module:

#-*-Coding:utf-8-*-
Import Psutil;
Import OS
Import Commmethod

"Get information about the machine's current process"
Def getcurrentprocessinfo ():
lst1= Psutil.pids ()
Lst1.sort ()
For I in Lst1:
temp = ""
Flag=true
# file name
filename = psutil. Process (i). Name ()

#文件全路径
FilePath = ""
#文件版本号
Version = ""
#安装时间
Installtime = ""
#访问时间
Accesstime = ""
#启动时间
StartTime = ""

Try
#文件路径
filepath = Psutil. Process (i). exe ()
#启动时间
StartTime = Commmethod.timestamptotime (psutil. Process (i). Create_time ())
#版本信息
Version = Commmethod.getfileversion (filepath)
Installtime = Os.path.getctime (filepath)
Accesstime = Os.path.getatime (filepath)
#把时间戳转为时间格式
Installtime = Commmethod.timestamptotime (installtime)
Accesstime = Commmethod.timestamptotime (accesstime)

Except
Flag=false
Finally
if (len (version) >0 and Len (installtime) >0):
print ' Id=%d,name=%s,filename =%s,version=%s, installtime=%s,accesstime=%s,starttime =%s '% (i,psutil. Process (i). Name (), Filename,version,installtime,accesstime,starttime)

Getcurrentprocessinfo ()

Python process information

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.