1833146 Members
3392 Online
110051 Solutions
New Discussion

Re: Killing process

 
SOLVED
Go to solution
Darren Murray_1
Frequent Advisor

Killing process

Hi,

I have a problem with users leaving a process behind if the application crashes. Once left behind this process chomps up cpu. The problem I have that a nightly job has the same process name so I need a script that will kill a process with the process name being mdb_x.27831 owned by any other username than qbdba.

The process is able to run for users other than qbdba but not for any longer than 60 minutes

I hope that makes sense.

7 REPLIES 7
Darren Murray_1
Frequent Advisor

Re: Killing process

Here is an example from top where you will see the same name but different user id's

The user whybroja should be killed

29896 whybroja 241 run 1563:34 98.81 98.64 mdb_x

13842 qbdba 148 20 5:13 10.26 10.24 mdb_x
Stefan Farrelly
Honored Contributor
Solution

Re: Killing process


Easy.
PID=$(ps -ef|grep mdb_x|grep -v grep|grep -v qbdba|awk '{print $2}')

Gives you the pid number to kill. It greps out the process owned by qbdba so if you have a runaway this will find it, then if the pid is non null kill it;

[ "$PID" -ne "" ] && kill $PID
Im from Palmerston North, New Zealand, but somehow ended up in London...
Tom Geudens
Honored Contributor

Re: Killing process

Hi,
There are several good threads about how to go about killing processes. Example : http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xc8d7a135f587d5118ff00090279cd0f9,00.html

I found this thread by doing a search on the forums with keywords : "kill grep process".

Hope it helps,
Tom
A life ? Cool ! Where can I download one of those from ?
Darren Murray_1
Frequent Advisor

Re: Killing process

Hi Stefan,

Thanks and I will assign points shortly!

This process can run for a time of about hour before you know that its a zombie.

How do I allow it to check that its been running for 60min + before killing it?

Cheers
Darren
Justo Exposito
Esteemed Contributor

Re: Killing process

Hi,

You can try this:

for i in $(ps -ef | grep "mbx_x*"| grep -v -e "qbdba" -e "grep" |sed -e 's/^/ /g' -e 's/\ \{1,\}/#/g' | cut -d"#" -f3)
do
echo $i
done

If all works, change the "echo $i" by "kill $i"

Regards,

Justo.
Help is a Beatiful word
Paula J Frazer-Campbell
Honored Contributor

Re: Killing process

Hi Darren

This script looks for running heavy cpu time users of a particular type and Zaps them.



The line:-
if [ $cpu00 -gt 180 ] - sets the cpu usage before the kill is activated ??? adjust to suit.

It is not the tidiest script but it works.

Test it well before use and echo back results before unhashing the Kill line.

HTH

Paula

------------------------cut here--------------
# CONNECTION MONITORING /CONTROL #
###########################################################
#!/usr/bin/sh
# Get info on the users
# Change the grep to suit particular user
#
ps -ef | grep " mdb_x.27831" | grep whybroja | grep -v grep | awk '{print $2, $5, $7}' | while read pid time cpu
do
# Strip the ':'
cpu00=`echo $cpu | sed 's/://'`
time00=`echo $time | sed 's/://'`
time000=`echo $time00 | sed 's/://'`
currenttime=`date "+%H%M%S"`
#
# Calculate total time connected
timeon=`print $currenttime - $time000|bc`
echo $timeon
#
# CPU usage bit
# Cpu usage limit
if [ $cpu00 -gt 180 ]
then
# Gracefull kill
echo $pid


# kill $pid


# Stronger kill (If required)
# sleep 5
# kill -9 $pid
fi
done

------------------------------------------------
If you can spell SysAdmin then you is one - anon
Paula J Frazer-Campbell
Honored Contributor

Re: Killing process

Darren

Welcome to the forum.



Paula
If you can spell SysAdmin then you is one - anon