in reply to Linux Process Start Time
Going with your original idea, I came up with this:
open my $pstat, "<", "/proc/$ARGV[0]/stat" or die "$!"; chomp(my $stat_line = <$procstat>); close $pstat; my $time_offset = (split / /, $stat_line)[21]; $time_offset = int $time_offset / 100; my $btime; open my $stat, "<", "/proc/stat" or die "$!"; while (<$stat>) { if (/^btime (\d*)/) { $btime = $1; last; } } close $stat; my $start_time = $time_offset + $btime; my $length = time - $start_time; print $length;
FYI, a jiffy is the time for one tick of the system interrupt timer, which happens to be 100Hz on my computer. That means this code is not portable. It would be if I knew a way to get the interrupt period at run time.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Linux Process Start Time
by pileofrogs (Priest) on Jul 27, 2009 at 17:50 UTC | |
by lostjimmy (Chaplain) on Jul 27, 2009 at 19:09 UTC |