Need an uptime command -- no, not 'uptime'
Fri, 2006-06-02 01:41
I need an uptime command that I can run, and not the 'uptime' command. I'm not interested in this case in how long the OS has been up, but how long a PID (Process ID) has been running in memory. Anyone got an idea?










I tried looking for such info in top or htop (a nicer version of top) thinking that the "TIME" field may be the uptime, but it turns out it is only the CPU time.
Another idea is the procinfo command, but that displays only general uptimes of the system and some other processes info..
Now I'm not sure if PIDs even track uptime information for themselves. I suppose they should.
Well.. I hope that at least takes you closer to the right idea. I'll let you know if I find out more.
There has to be a way..
just a lucky guess: I think
ls -l /proc | grep <pid>
will show you what time <pid> was created
just a lucky guess: I think
ls -l /proc | grep
will show you what time was created
Hah, that's pretty creative. I like that
All ye need to do now is run that through a script to parse that timestamp into hours.
just a few simple commands
#### function determines uptime of a specified process ($1).
# tested in zsh 4.3.2 and bash 3.1 (Debian GNU/Linux SID)
###
function pidup ()
{
(( secs = $( date +%s ) - $( date --date="$( ls -l /proc | awk "/$1/ { printf (\"%s %s\",\$6,\$7) ; }" )" +%s ) ))
echo up for $(( $secs / 3600 ))h $(( ($secs % 3600) / 60 ))m $(( $secs % 60 ))s
}
yay. I would've wanted to try it but I guess you beat me to it.