Skip to content

Instantly share code, notes, and snippets.

@rcalsaverini
Created June 15, 2012 14:33
Show Gist options
  • Save rcalsaverini/2936760 to your computer and use it in GitHub Desktop.
Save rcalsaverini/2936760 to your computer and use it in GitHub Desktop.
Get running time of a process given a pid
#!/bin/bash
pidlist=`ps ax | grep -i -E $1 | grep -v grep | awk '{print $1}' | grep -v PID | xargs echo`
for pid in $pidlist; do
sincetime $pid
done
#!/bin/bash
init=`stat -t /proc/$1 | awk '{print $14}'`
curr=`date +%s`
seconds=`echo $curr - $init| bc`
name=`cat /proc/$1/cmdline`
echo $name $seconds
@rcalsaverini
Copy link
Author

These are two simple scripts to check the age of running processes. The command:

sincetime <PID> 

should output the age of the process with pid= in seconds.

The command:

greptime <pattern>

where is a string or regular expression, will output all processes matching the pattern and their ages in seconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment