3

I'm Looking for a way to show the time a certain process is in it's current state.
At the moment, I'm using the command:

ps -A -o uname,pid,state,etime,cmd | grep -e pbs | egrep -v "grep"

Which give me output like this:

root      1613 S  4-00:16:59 /usr/sbin/pbs_server
root     13508 S  1-18:13:37 /usr/sbin/pbs_sched
root     15344 R    01:09:51 /usr/sbin/pbs_mom

This tells me pbs_mom is running for approx one hour. However, I need to know for how long it has this running state. Is there a way to get this using only the command-line? (since I'm intending to use it in a script)

  • How long it has had the current state or how long it has had a running state over all? The former might not be possible, the latter would be the total of real+sys for that process. – muru Feb 16 '15 at 12:29
  • I'm looking for how long it has had the current state – user1834095 Feb 16 '15 at 12:47
  • I don't think that data is maintained anywhere - you'll have to monitor the process's status yourself. – muru Feb 16 '15 at 12:48
  • Okay, and the other option? Could you make a separated comment with the command-line I need to get the total time of running-state? Perhaps it can be of use anyway (if not for me, then maybe for someone else). – user1834095 Feb 16 '15 at 12:56
  • That's easy - just tack on bsdtime to the ps fields. – muru Feb 16 '15 at 12:57
1

Sadly it is not possible to tell how long the process has been in the current state (or at what time the process state changed last) - the kernel doesn't keep this kind of history.

Imagine the vast amount of overhead (processor-time-wise and memory-wise) to keep the timestamps of every context-switch (several hundred to several thousand per second).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.