As fidesachates suggested, if you are on Linux, you could try parsing the time output of ps like this.
perl -we 'use Date::Manip::Date; my $pid = shift; my $sstart = readpip
+e("TZ=UTC ps --no-headers --format lstart --pid " . (0+$pid)); my $st
+art = Date::Manip::Date->new($sstart, [SetDate => "zone,UTC"]); my $e
+start = $start->printf("%s"); print "process $pid started at epoch ti
+me $estart\n";' 1967
Alternately let's skip running ps and emulate what it does (except that it actually obtains the Hertz value in a different way).
perl -we 'use POSIX(); my $pid = shift; my $seconds_since_boot; { open
+ my $UPTIME, "<", "/proc/uptime" or die; <$UPTIME> =~ /(\S+)/ or die;
+ $seconds_since_boot = 0+$1; } my $start_time; { open my $STAT, "<",
+"/proc/" . (0+$pid) . "/stat" or die; <$STAT> =~ /\)(.+)/ or die; $st
+art_time = 0+(split " ", $1)[19]; } my $Hertz = POSIX::sysconf(POSIX:
+:_SC_CLK_TCK()); my $start_epoch = time() - $seconds_since_boot + $st
+art_time / $Hertz; print "process $pid started at epoch time $start_e
+poch\n"' 1967
Note that this may have up to one second of error.
One would think this problem has an easier solution, and maybe someone else will show one, but I couldn't get anything simpler than this.
Update 2012-04-13: a somewhat related later question is A regular expression that will work for (hh:)mm:ss [converting clock time to seconds].
|