代码:
#!/usr/bin/python
#_*_encoding:utf-8_*_
#print the process create time by the process name .
import psutil,datetime,sys
if sys.argv[1] == "-h":
print "Usage:%s -h|httpd|nginx|mysqld|and so on" % sys.argv[0]
print "例如:python processt.py httpd #查看httpd进程创建的时间戳。"
exit()
def processt(name,):
pid = psutil.pids()
for i in pid:
pn = psutil.process(i)
if pn.name() == name:
r = datetime.datetime.fromtimestamp(psutil.process(i).create_time()).strftime("%y-%m-%d;%h:%m:%s")
print name + "'s create time is : " + r
processt(sys.argv[1])