How to display processes which have been running for more than a X hours?


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 2 Weeks Ago
How to display processes which have been running for more than a X hours?

Hi,

Is it possible to display processes which have been running for more than a 5hrs using a variation of the ps -ef command?

Regards,

Manny
# 2  
Old 2 Weeks Ago
The ps command output varies per platform, so could you specify what OS you are using?

On Linux you could try:
Code:
ps -eo pid,etimes | awk '$2/3600>=5{print $1}'

# 3  
Old 2 Weeks Ago
Code:
ps -eo pid,etime

and the "no header" variant
Code:
ps -e -o pid= -o etime=

are quite portable (Posix standard).
The usual output format for times is D-HH:MM:SS
where the D- (=days) prefix is only printed if D > 0
This User Gave Thanks to MadeInGermany For This Post:
Scrutinizer (2 Weeks Ago)
# 4  
Old 2 Weeks Ago
Sorry, i should have said, this command needs to run on a unix (solaris) operating system.

Thanks.
# 5  
Old 2 Weeks Ago
Quote:
Originally Posted by mantas44
Sorry, i should have said, this command needs to run on a unix (solaris) operating system.

Thanks.
So, since you're using a Solaris/SunOS system, instead of using:
Code:
ps -eo pid,etime

and the "no header" variant
Code:
ps -e -o pid= -o etime=

use:
Code:
/usr/xpg4/bin/ps -eo pid,etime

and the "no header" variant
Code:
/usr/xpg4/bin/ps -e -o pid= -o etime=

# 6  
Old 1 Week Ago
Have to add that even the HH: is usually omitted if HH is zero.
A suitable postprocessing with awk:
Code:
ps -e -o pid= -o etime= | /usr/xpg4/bin/awk '{ n=split($NF, A, /[-:]/); seconds=(A[n]+60*(A[n-1]+60*(A[n-2]+24*A[n-3]))) } (seconds > 5*3600) { print $1 }'

The { print $1 } prints only the pids.
Another example with two more columns and printing everything:
Code:
ps -e -o pid= -o user= -o args= -o etime= | /usr/xpg4/bin/awk '{ n=split($NF, A,  /[-:]/); seconds=(A[n]+60*(A[n-1]+60*(A[n-2]+24*A[n-3]))) } (seconds > 5*3600)'

BTW Sun made the /usr/bin/ps Posix compliant; there is no /usr/xpg4/bin/ps. But df, find, awk, and >60 more Posix compliant commands live in /usr/xpg4/bin/

Last edited by MadeInGermany; 1 Week Ago at 09:18 AM.. Reason: $NF and another example.
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
At command not running out of hours Delboy4000 UNIX for Dummies Questions & Answers 4 07-03-2015 08:37 AM
How to display all daemon processes in priority order? hce Linux 4 06-16-2014 09:42 PM
Print only processes running for more than 24 hours anil510 Shell Programming and Scripting 9 09-07-2013 03:12 AM
Display date from twelve hours ago pareshkp Shell Programming and Scripting 6 07-24-2013 11:17 PM
Running processes batas Linux 4 04-11-2013 09:27 AM
Running processes on GZ/LZ batas Solaris 3 02-12-2013 05:31 AM
find the no of processes that ran 2 hours before or earlier jansat UNIX for Dummies Questions & Answers 3 02-14-2012 12:12 PM
List of Running Jobs In Last 4 Hours rajubollas Shell Programming and Scripting 2 08-19-2011 11:50 PM
Capture the running process for 2 hours sarathkumar Shell Programming and Scripting 1 04-01-2011 05:11 AM
Capture running process or 2 hours with an interval of 10 sec sarathkumar Shell Programming and Scripting 1 03-31-2011 02:41 PM
Capture running process for 2 hours with an interval of 10 sec sarathkumar UNIX for Dummies Questions & Answers 0 03-31-2011 02:02 PM
how to know the running processes. rajesh_pola Shell Programming and Scripting 1 03-10-2011 10:37 AM
Scripting Help - Display Processes isxrc Shell Programming and Scripting 1 01-18-2010 11:25 PM
How to display what processes, users have opened at a given time gabibyte Shell Programming and Scripting 5 11-02-2009 02:57 PM
Spawing multiple display processes from one shell. JoeTheGuy UNIX for Advanced & Expert Users 4 10-02-2002 10:35 PM