Skip to content

Instantly share code, notes, and snippets.

@westhood
Created July 9, 2011 13:36
Show Gist options
  • Select an option

  • Save westhood/1073585 to your computer and use it in GitHub Desktop.

Select an option

Save westhood/1073585 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment