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
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
The ps command output varies per platform, so could you specify what OS you are using?
On Linux you could try:
ps -eo pid,etimes | awk '$2/3600>=5{print $1}'
ps -eo pid,etime
and the "no header" variant
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
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:
ps -eo pid,etime
and the "no header" variant
ps -e -o pid= -o etime=
use:
/usr/xpg4/bin/ps -eo pid,etime
and the "no header" variant
/usr/xpg4/bin/ps -e -o pid= -o etime=
Have to add that even the HH:
is usually omitted if HH is zero.
A suitable postprocessing with awk:
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:
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/