Print only processes running for more than 24 hours


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print only processes running for more than 24 hours
# 1  
Old 09-06-2013
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.
Code:
 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 sed/awk.
# 2  
Old 09-06-2013
Try this
Code:
ps -eo pid,pcpu,pmem,user,args,etime,cmd --sort=start_time | awk 'substr($0,54,2)>=24'

My PS get time at position 54, your my differ.
# 3  
Old 09-06-2013
Jotne,

Thanks, but not getting correct result.
# 4  
Old 09-06-2013
Code:
ps -eo pid,etime,args | awk 'substr($2,1,index($2,"-")-1)>1'


Last edited by MadeInGermany; 09-06-2013 at 06:22 AM.. Reason: x= not needed here
# 5  
Old 09-06-2013
Thanks, but not all process is showing up in result.

Is there a way to list with seconds elapsed since a process started, rather than like day-hour:minute:seconds
Code:
1 1-00:00:00 init [3]

Should be like below. The above process is running for 1 day, 0 hour, 0 minutes, 0 seconds. So total seconds it has been running is 86400 seconds. So the ps result should show like below.
Code:
86400 init [3]

# 6  
Old 09-06-2013
Then let awk calculate that in seconds.
Code:
ps -eo pid,etime,args | awk '
(x=substr($2,1,i=index($2,"-")-1))>1 {
 y=substr($2,i+2); split(y,Y,":")
 $2=60*(60*(24*x+Y[1])+Y[2])+Y[3]
 print
}'

# 7  
Old 09-06-2013
@anil510
Post the output of ps -eo pid,pcpu,pmem,user,args,etime,cmd --sort=start_time
This way we need not guess what you see.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

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

HI can someone help me to check the process running more than 2 hours. I have the below command which shows the time and process id, however, I only need the processes running more than 2 hours. (8 Replies)
Discussion started by: Vinod
8 Replies

2. 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

3. Shell Programming and Scripting

Can anyone help me to print UNIX epoch time to days,hours,min,sec ?

I have unix epoch time 1441678454803, Can you please help me to print this time in below format ? DAY,HOUR,MIN,SEC Appreciate your help!!! Thanks, Prince (7 Replies)
Discussion started by: prince1987
7 Replies

4. UNIX for Dummies Questions & Answers

At command not running out of hours

Hi All, new to the forum and new to Unix but I have an issue which is annoying on a new level. I have included a short and full version for anyone needing more information. Short Version I am running a set of scripts that work and run fine. one of the scripts arranges the first... (4 Replies)
Discussion started by: Delboy4000
4 Replies

5. 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

6. Shell Programming and Scripting

List of Running Jobs In Last 4 Hours

Hi Experts, Please help me in this. I am trying this code on AIX 5.3. I need list of jobs that executed in last 4 hours. I have a schedule on this script - cron executes it and sends mail to me for every 2 hours. I have a Job time and have around 100 jobs those execute daily. What all i need... (2 Replies)
Discussion started by: rajubollas
2 Replies

7. Shell Programming and Scripting

Capture the running process for 2 hours

Hi, How can i capture the running process for 2 hours. Thanks in advance.:b: (1 Reply)
Discussion started by: sarathkumar
1 Replies

8. Shell Programming and Scripting

Capture running process or 2 hours with an interval of 10 sec

Hi, Can any one help me on this. How to capture the running process for two hours with an interval of 10 sec. Thanks in andvance (1 Reply)
Discussion started by: sarathkumar
1 Replies

9. UNIX for Dummies Questions & Answers

Capture running process for 2 hours with an interval of 10 sec

Hi, Can any one help me on this. How to capture the running process for two hours with an interval of 10 sec. Thanks in andvance Double post, continued here, thread closed (0 Replies)
Discussion started by: sarathkumar
0 Replies

10. UNIX for Dummies Questions & Answers

How do you print the number of processes that each user is currently running in Unix?

Ok, so I know there's a way to do this, but I've been trying to find out all afternoon with no luck. I think it should print out something like this: 1 bin 2 daemon 6 duo Where the numbers on the left are the number of processes being run by the user whose name is listed on the right. Is... (4 Replies)
Discussion started by: Duo11
4 Replies
Login or Register to Ask a Question