We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5e6badb commit 7ccfe40Copy full SHA for 7ccfe40
py2018/proc_start_time.py
@@ -0,0 +1,23 @@
1
+'''
2
+get the start time of a process
3
+e.g. python proc_start_time.py -p 12345
4
5
+import argparse
6
+import psutil
7
+import os
8
+import time
9
+
10
11
+def get_start_time(pid):
12
+ ''' return the start time in human readable string '''
13
+ p = psutil.Process(int(pid))
14
+ return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(p.create_time()))
15
16
17
+if __name__ == '__main__':
18
+ parser = argparse.ArgumentParser()
19
+ parser.add_argument("-p", "--pid", help="PID of a process")
20
+ args = parser.parse_args()
21
+ if not args.pid:
22
+ args.pid = os.getpid()
23
+ print get_start_time(args.pid)
0 commit comments