How to check the processes running longer than 2 hours.?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to check the processes running longer than 2 hours.?
# 8  
Old 07-22-2019
Thank you, however, I'm not able to send get the output of the mentioned command.

Code:
bash-3.2# ps -efo pid,comm,etimes | awk '$NF > 7200'
ps: unknown output format: -o etimes
usage: ps [ -aAdeflcjLPyZ ] [ -o format ] [ -t termlist ]
        [ -u userlist ] [ -U userlist ] [ -G grouplist ]
        [ -p proclist ] [ -g pgrplist ] [ -s sidlist ] [ -z zonelist ]
  'format' is one or more of:
        user ruser group rgroup uid ruid gid rgid pid ppid pgid sid taskid ctid
        pri opri pcpu pmem vsz rss osz nice class time etime stime zone zoneid
        f s c lwp nlwp psr tty addr wchan fname comm args projid project pset

It is working when I remove 's' from etimes. But I'm not sure this is giving the correct output I need

Code:
bash-3.2# ps -efo pid,comm,etime | awk '$NF > 7200'
  PID COMMAND                                                                              ELAPSED
 7053 Command                                   96-00:56:14
17647 command                                    76-00:54:48
13030 command                                                              8-18:00:49
29871 command                                     73-00:53:42
25722 command                                    74-00:53:45
10527 command                                   86-23:52:54
27597command                                    86-21:12:59
13665 command                                    77-00:54:40
24848command                                     86-21:38:43



Also, Madeln can you please explain this command

Code:
ps -eo pid,comm,etime | awk '$3~/^[2-9][0-9]*-/{print $1,$2,$3}'


Last edited by RavinderSingh13; 07-22-2019 at 11:51 AM..
# 9  
Old 07-22-2019
The awk checks field 3 (etime) against a regular expression (RE) that checks the digits before a - character. But - I misread your first post - that's days, not hours!
Also there is a bug in the RE, should be
Code:
ps -eo pid,comm,etime | awk '$3~/^([2-9]|[0-9][0-9]+)-/{print $1,$2,$3}'

A digit in the range [2-9] or two+ digits between the start of the field and a - character.
Still this is days.
For hours, the RE would become too complicated.
So here is another one that computes the time in seconds:
Code:
ps -e -o pid= -o comm= -o etime= | awk '{n=split($3,e,"[-:]"); elapsed=e[n]+60*(e[n-1]+60*(e[n-2]+24*e[n-3]))} elapsed>7200 {print $1,$2,$3,elapsed}'

The ps is a bit longer, omits the header in a portable way.
The awk splits the field 3 into an array, delimited by the RE [-:] (a - or a : character).
Then it multiplies the array elements, so the are in seconds. Stores the sum in the variable" elapsed".
Then print if "elapsed" is greater than 7200.
It prints all three fields from the ps command, plus the "elapsed" variable. Omit what you don't need!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk program date function no longer running

I work at a company that uses a program written in AWK to track various data and prepare reports. Worked with this program for three years plus (the author is no longer with us) and the YTD Production report will not return a report with a date after 123119. This is a problem. Below is the (I... (3 Replies)
Discussion started by: paulgdavitt
3 Replies

2. UNIX for Beginners Questions & Answers

Check processes running on remote server

Hello Guys, I need some help to find out if processes are running on remote server or not. I could do 'ssh' to do that but due to some security reasons, I need to avoid the ssh & get result from remote server. Could you please suggest some that can be done without ssh or similar sort of... (8 Replies)
Discussion started by: UnknownGuy
8 Replies

3. UNIX for Beginners Questions & Answers

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 (5 Replies)
Discussion started by: mantas44
5 Replies

4. Shell Programming and Scripting

Check Running Processes

I want to check how many processes are running with same names and get their respective counts. ps -ef|grep -Eo 'process1|process2|process3| '|sort -u | awk '{print $2": "$1}' Output would look like : $ ps -ef|grep -Eo 'process1|process2|process3| '|sort | uniq -c | awk '{print $2":... (8 Replies)
Discussion started by: simpltyansh
8 Replies

5. AIX

Need to check long running processes on the database server and the os is AIX

Hello, Please help me with a script with which I can check long running processes on the database server and the os is AIX. Best regards, Vishal (5 Replies)
Discussion started by: Vishal_dba
5 Replies

6. Shell Programming and Scripting

Print only processes running for more than 24 hours

How can I print ONLY processes running for more than 24 hours. Using ps command or any other method I use this to get a whole list. ps -eo pid,pcpu,pmem,user,args,etime,cmd --sort=start_time We can also sort the outout of the above command to list processes older than 24 hours using... (9 Replies)
Discussion started by: anil510
9 Replies

7. UNIX for Dummies Questions & Answers

find the no of processes that ran 2 hours before or earlier

Is there a way to find out the total no of processes that were running ? - 2 or 3 hours before - list those no of processes (3 Replies)
Discussion started by: jansat
3 Replies

8. UNIX for Dummies Questions & Answers

How to check the status of the processes running for the current user?

Hi All, I am new to unix. Can anyone tell me "How to check the status of the processes running for the current user?" Regards, Ravindaran S (1 Reply)
Discussion started by: ravind27
1 Replies

9. Shell Programming and Scripting

Script to check running processes on remote server.

Hi, I am trying to write a script, which queries a db to get the names of processes, stores it in a file and then checks if that process is running on a remote server. However I am not getting it right, could anyone help me out. #!/bin/sh echo "select Address from Device where Cust =... (5 Replies)
Discussion started by: amitsayshii
5 Replies

10. UNIX for Advanced & Expert Users

scripts no longer running (solaris 8)

hello: I am a somewhat experienced unix user, but brand new to this forum. I am encountering a strange new problem. I have a shell script called foo.ksh it has been running for years (literally) on my Sun (Solaris 8) machine. Recently we put a version of samba on this machine to... (3 Replies)
Discussion started by: smcadoo
3 Replies
Login or Register to Ask a Question