Check for long running process on AIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check for long running process on AIX
# 1  
Old 11-21-2013
Check for long running process on AIX

I want to write a shellscript which determines if a particular process is long running than my specified threshold time.

Code:
Eg:
My process name is "prsd" and is expected to run for 15 mins and completes. If I set a threshold limit of 1 hour,
and how we can the get output of the long running process "prsd" assuming it is running more than 2 hours.

Please help. Thanks in advance.
# 2  
Old 11-21-2013
You can rewrite prsd to flush its output buffers every x minutes, or to flush its output buffers and exit if it receives a certain signal. Then after having updated prsd you can write a shell script to get prsd's process id from ps command output and send that signal to the instance of prsd you want to kill.

There is no way, in general, to write a shell script that will reach into another process and force that process to write out what it was working on.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 11-21-2013
You could try something like this (don't have AIX available to test it), this will list PID of any prsd process running for more than 2 hours

Code:
ps -eo "comm pid etime" | awk '
BEGIN {split("1 60 3600 86400",M)}
/^prsd/{
    secs=0;
    for(s=v=split($3, T, "[:-]");v;v--)
        secs +=M[1+s-v]*T[v];
    if(secs > 3600*2) print "Process #" $2 " running for " secs " seconds"
}'

These 2 Users Gave Thanks to Chubler_XL For This Post:
# 4  
Old 11-21-2013
The ps command has an elapsed time option that shows how long a process has been running.

i.e.
Code:
ps -eo etime,user,pid,args | grep [p]rsd

The first column shows how long the process has been running.
This User Gave Thanks to in2nix4life For This Post:
# 5  
Old 11-21-2013
Quote:
Originally Posted by in2nix4life
The ps command has an elapsed time option that shows how long a process has been running.

i.e.
Code:
ps -eo etime,user,pid,args | grep [p]rsd

The first column shows how long the process has been running.
Attention: [p] has a special meaning to the shell - must be quoted "[p]rsd"!
Otherwise there is not only the overhead that the shell searches the current work directory for matches. If it really finds a matching prsd it will replace the [p]rstd with it. And run into the race condition that grep can match itself in the ps output.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check status of long running multiple curl commands in shell script

I am working on script. it reads a file which contains multiple lines Ex; curl --write-out %{http_code} --silent --output /dev/null http://hostname:port/input=1 curl --write-out %{http_code} --silent --output /dev/null http://hostname:port/input=2 curl --write-out %{http_code} --silent ... (2 Replies)
Discussion started by: oraclermanpt
2 Replies

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

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

4. UNIX for Dummies Questions & Answers

How a process can check if a particular process is running on different machine?

I have process1 running on one machine and generating some log file. Now another process which can be launched on any machine wants to know if process1 is running or not and also in case it is running it wants to stream the logs file generated by process1 on terminal from which process2 is... (2 Replies)
Discussion started by: saurabhnsit2001
2 Replies

5. Shell Programming and Scripting

Monitor a long running process

Gurus, I am writing a shell script that will be used to automate cold backup of an Oracle Database. The database size is around 300G and will take around 5-6 hours to copy. I have finished the script till the copy of the datafiles. Now, I am stuck at the point where I need to monitor the... (4 Replies)
Discussion started by: sunpraveen
4 Replies

6. Shell Programming and Scripting

Check if Process is running

Hi , I have a csh code below which check the process if it's running. Can any expert advise me on the following: 1) what does this notationmean ">!" and how is it different from the append ">" notation ? 2) how does "setenv" work in this code ? # Check whether there is a running... (3 Replies)
Discussion started by: Raynon
3 Replies

7. UNIX for Advanced & Expert Users

How to check since when (for how long) a particular process is running ?

How do I check if a particular process is running from a certain date and time ? (2 Replies)
Discussion started by: hpuxlxboy
2 Replies

8. UNIX for Advanced & Expert Users

how to check how long the process has been running.

I have a requirement to check how long a process is running on unix system.If i use ps -ef i am getting the following message guest 2453638 1998920 0 16:16:05 - 0:00 dsapi_slave 9 8 0 but this is showing only time not the date.Can any one please advice me any script to find out how... (2 Replies)
Discussion started by: ukatru
2 Replies

9. Shell Programming and Scripting

check process running

I have this script: ------------------------------------------------------- #!/bin/ksh # if ] || ] then echo "Executing main_load.sh script" /usr1/psc_load/jobs/cron/main_load.sh "ods" else echo "File not found, do nothing" fi exit 0 ... (4 Replies)
Discussion started by: rose1207
4 Replies
Login or Register to Ask a Question