Created
August 28, 2012 17:08
-
-
Save waffle2k/3500872 to your computer and use it in GitHub Desktop.
Age of a process in seconds on the Linux proc system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
$pid = shift || die "You must specify a pid\n"; | |
die "Pid $pid does not exist\n" unless -e "/proc/${pid}/"; | |
my $s = `cat /proc/${pid}/stat`; | |
my @a = split( /\s+/, $s ); | |
my $jiffies = int( $a[22] / 1000 ); | |
my $u = `cat /proc/uptime`; | |
my @ua = split( /\s+/, $u ); | |
my $uptime = int( $ua[0] ); | |
my $now = time(); | |
my $launched = $now - $uptime + $jiffies; | |
my $age = $now - $launched; | |
print "Age: $age\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment