Skip to content

Instantly share code, notes, and snippets.

View cathay4t's full-sized avatar

Gris Ge cathay4t

View GitHub Profile
@westhood
westhood / proc_starttime.py
Created July 9, 2011 13:36
get start time of process on linux via python
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