Process running more than require time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Process running more than require time
# 1  
Old 03-14-2013
Code Process running more than require time

Frineds I need assistance in writing a script . Newbie to scripting.

How to find list of processes that are running more than an hour . Below i used the step to get the etime and stime . Now by getting the result i need to display longer time process with full listing.

Code:
ps -aef -o user,pid,etime,stime,args |grep <process name> | awk '{print $3}'

which gives the below result

Code:
42:03
3-06:21:33
01:08:05
18:23
00:00
01:07:55
59:06
58:13

Thank you in advance

Last edited by Scrutinizer; 03-15-2013 at 01:06 AM.. Reason: code tags
# 2  
Old 03-14-2013
Why not do print $2,3 to get both fields?
# 3  
Old 03-14-2013
I did that but my result should show only the PID's which are taking longer time.
# 4  
Old 03-14-2013
And you need the PID too, not just the time...

Code:
awk '{ split($3,A,":"); T=(A[1]*60)+A[2]; $0=$2" "$3 } T>60'

# 5  
Old 03-14-2013
Note that using -f and -o together is not portable. On many systems that will give you a full listing with the additional fields specified by -o appended to the end the line of normal -f output. If you just want the fields you specified listed for any process that has been running for an hour or more, try:
Code:
ps -ae -o user,pid,etime,stime,args | awk 'split($3,f,/[-:]/)>2'

# 6  
Old 03-14-2013
Or use:
Code:
ps -eo user,pid,etime,stime,args | awk '{n=split($3,A,":");$0=$2" "$3}n>=3'

# 7  
Old 03-15-2013
Yoda Thank you for your reply but I get an error saying

Code:
bash-2.05$ ps -eo user,pid,etime,stime,args | awk '{ split($3,A,":"); T=(A[1]*60)+A[2]; $0=$2" "$3 } T>60'
awk: can't set $0
 record number 1

---------- Post updated at 09:26 AM ---------- Previous update was at 09:24 AM ----------

Don Cragun Thank you for your reply but when i use your command i get an error

Code:
bash-2.05$ ps -ae -o user,pid,etime,stime,args | awk 'split($3,f,/[-:]/)>2'
awk: syntax error near line 1
awk: bailing out near line 1

---------- Post updated at 09:28 AM ---------- Previous update was at 09:26 AM ----------

Corona688 thank you for your response. I get an error below.

Code:
bash-2.05$ ps -ae -o user,pid,etime,stime,args | awk '{ split($3,A,":"); T=(A[1]*60)+A[2]; $0=$2" "$3 } T>60'
awk: can't set $0
 record number 1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Killing the process if running for long time in script

I am running a script which will read the data from fail line by line and call the Java program by providing the arguments from the each line. The Java code is working fast for few records and for some records its getting hanged not providing response for morethan one hour. Currently am... (4 Replies)
Discussion started by: dineshaila
4 Replies

2. Shell Programming and Scripting

Get how much time process has been running in seconds

I use this command to get the time elapsed for a process ps -eo pid,pcpu,pmem,user,args,etime,cmd --sort=start_time | grep perl It gives in format 19990 0.0 0.0 user /usr/bin/php 5-09:58:51 /usr/bin/php I need in seconds. Please use CODE tags for sample input and output as well... (2 Replies)
Discussion started by: anil510
2 Replies

3. Shell Programming and Scripting

Process running time by taking user input

Need help in scripting . Below is the situation and need your inputs Checking all the processes, scripts running time based on user input time . Below Example ps -aef -o user,pid,etime,stime,args| grep sleep <user> 28995 01:24 14:14:39 sleep 120 <user> 29385 00:52 14:15:10... (8 Replies)
Discussion started by: ajayram_arya
8 Replies

4. Shell Programming and Scripting

Help with kill a specific process after certain running time

Hi, Do anybody experience to write a bash script in order to kill a specific process (java) after certain time of running? eg. java java.jar task_run.txt I will run a java program (java.jar) which will run a long list of process (task_run.txt) one by one. I plan to terminate the java... (5 Replies)
Discussion started by: perl_beginner
5 Replies

5. Shell Programming and Scripting

Running a process based on time

Hello All, My script is nearly complete, there is just one last piece that needs to be added in. I need to check for the time, and if it is lets say for example. Sunday at 5:00AM, my script cannot run. I would assume it would be something like this, parden the terrible pseudocode ... (7 Replies)
Discussion started by: jeffs42885
7 Replies

6. UNIX for Dummies Questions & Answers

How to get the start time for a JAVA Main running process

I have a script that executes a MAIN JAVA FILE It does check if the process is already running or not by using this code w_pid=`ps -efx | grep -v grep | grep "FileTransactionArchiveMain dvlp"|awk '{print $11}'` if then #echo 'Another instance is running.' exit fi Now I... (1 Reply)
Discussion started by: akabir77
1 Replies

7. UNIX for Dummies Questions & Answers

how to get start time of a running process

I am trying to see if a process is running what was its start time. here is the code that I am using if then echo 'Gateway output processing started.' else VAR=$(ps -ef | grep batch_output_x ) ... fi now the problem i see is when the process is running i get two... (3 Replies)
Discussion started by: akabir77
3 Replies

8. Shell Programming and Scripting

keeping 10 process running at the same time

Hi guys, I neet to run sqlldr to charge about 50,000 files every day to my DWH, so I need to make an script to keep about 100 processes of sqlldr running at the same time. So, the issue is that i've been trying for a few days to make an script which can keep that amount of processes running, so... (2 Replies)
Discussion started by: razziel
2 Replies

9. UNIX for Dummies Questions & Answers

is there any way to know how much time process was running from the moment it started

i have process that was started few days ago , is there way to know by its id how long it was alive in the system ? Thanks (2 Replies)
Discussion started by: umen
2 Replies

10. UNIX Desktop Questions & Answers

Does it require each x-client sould run in separate process?

Hi Every One, I got a Basic doubts about clients on X-Server environment. 1) First of all what is mend by one client. (as per my understanding one application which is connected to X-server). 2) if i say two clients connected to my X-Server from the same machine, does it mean that two... (0 Replies)
Discussion started by: ps_sureshreddi
0 Replies
Login or Register to Ask a Question