Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Created August 28, 2012 17:08
Show Gist options
  • Save waffle2k/3500872 to your computer and use it in GitHub Desktop.
Save waffle2k/3500872 to your computer and use it in GitHub Desktop.
Age of a process in seconds on the Linux proc system
#!/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