Operating System - Linux
1827892 Members
1703 Online
109969 Solutions
New Discussion

Re: Script or command to find amount of real time for a process

 
J Greg Wallace
Occasional Contributor

Script or command to find amount of real time for a process

Is there a command to find the amount of real time a process has been running?

Or does anyone have a script example to find this information?

Trying to write a script to look for processes that have been running greater than or equal to 12 hours.
1 REPLY 1
James R. Ferguson
Acclaimed Contributor

Re: Script or command to find amount of real time for a process

Hi:

If you use the XPG4 (UNIX95) mode of 'ps' you can output your time in 'days-hours:minutes:seconds'. This field is then easy to parse for computation purposes.

Compare these:

# ps -ef |grep xntpd
root 1671 1 0 Mar 3 ? 28:28 /usr/sbin/xntpd -x

...versus:

# UNIX95= ps -e -o pid -o etime -o comm|grep xntpd
1671 100-18:59:40 xntpd

Set the UNIX95 variable *only* for the duration of the 'ps' command as shown. There is no semicolon after the assignment operator and before the 'ps'.

If you don't want headings added to the output, do:

# UNIX95= ps -e -o pid= -o etime= -o comm=

See the manpages for 'ps' for more information.

Regards!

...JRF...