Skip to main content
Welcome guest. | Register | Login | Post

Need an uptime command -- no, not 'uptime'

5 replies [Last post]
supermike's picture
Offline
Joined: 2006-02-17

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?

 

libervisco's picture
Offline
Joined: 2006-05-04
I tried looking for such

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..

tbuitenh's picture
Offline
Joined: 2005-12-21
just a lucky guess: I

just a lucky guess: I think

ls -l /proc | grep <pid>

will show you what time <pid> was created

Offline
Joined: 2006-01-02
tbuitenh wrote:just a
'tbuitenh' wrote:

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 Smiling

All ye need to do now is run that through a script to parse that timestamp into hours.

free-zombie's picture
Offline
Joined: 2006-03-08
just a few simple commands

just a few simple commands Eye

###
# 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
}
Offline</