Operating System - HP-UX
1844609 Members
2208 Online
110233 Solutions
New Discussion

Re: script for terminate dead process

 
SOLVED
Go to solution
peterchu
Super Advisor

script for terminate dead process

In my system , there are a system user "cronusr" , it is mainly to run the crontab job in the database .Sometimes the cronjob process will be failure ( due to some reason ) so that many cronusr process are in the system , it affect other process in the system ,

I am looking for to have a script that can kill the process - the process owner is cronusr and it is idle for one hour ( I think it can check by ps -aux |grep pid , if the status is R , then it is running , if it is S , then it is sleep and the process can be termiated ) , could suggest the script for the case ? thx in advance.
4 REPLIES 4
Alex Lavrov.
Honored Contributor
Solution

Re: script for terminate dead process

Try to get all the proccesses that you wish to reminate with "ps" program.

Probably you'll need to set UNIX95=1 env variable, to enable XPG4 with more options.

Then parse the output of ps with grep/awk etc, get PID and kill that proccess.

If you'll post here the sample of ps output that you are interested to parse, I can suggest a few things, because from the info you supplied I doubt that I can give you proper "ps" line, so it won't kill some important things ;)
I don't give a damn for a man that can only spell a word one way. (M. Twain)
Muthukumar_5
Honored Contributor

Re: script for terminate dead process

You can kill process as like as,

for pid in `ps -el -u cronuser | awk '{ if ( $2 == "S") { print $4 }}'`
do
kill -9 $pid
done

hth.
Easy to suggest when don't know about the problem!
Simon Hargrave
Honored Contributor

Re: script for terminate dead process

The S state is not useful for this because a running process is constantly switching between R and S when making system calls.

It is easier to find process "elapsed" time rather than idle time, so for example if you know your process should never take more than 2 hours you could use: -

UNIX95= ps -o pid,etime -u cronusr

This will show you the PID and elapsed time for every process of cronusr. From this you can determine which ones have run >2 hours and kill as necessary.
harry d brown jr
Honored Contributor

Re: script for terminate dead process


Wouldn't it be easier to fix the problem rather than create another process to monitor the one that has issues with it?

It's like nuking the planet to save the whales - over kill.

live free or die
harry d brown jr
Live Free or Die