Created
July 9, 2011 13:36
-
-
Save westhood/1073585 to your computer and use it in GitHub Desktop.
get start time of process on linux via python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def proc_starttime(pid): | |
| p = re.compile(r"^btime (\d+)$", re.MULTILINE) | |
| m = p.search(open("/proc/stat").read()) | |
| btime = int(m.groups()[0]) | |
| clk_tck = os.sysconf(os.sysconf_names["SC_CLK_TCK"]) | |
| stime = int(open("/proc/%d/stat" % pid).read().split()[21]) / clk_tck | |
| return btime + stime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment