Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Linux Process Start Time

by lostjimmy (Chaplain)
on Jul 27, 2009 at 17:32 UTC ( [id://783614]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://783614]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2026-04-17 13:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.