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

    ++

    Nice!

    Maybe /proc/cpuinfo? Non-portable, I know.

      The only place I know of that makes that information available is actually in /proc/config.gz. So, theoretically, you could get the timer frequency with zgrep CONFIG_HZ= /proc/config.gz, but it really doesn't seem like the best way of doing this.