Computing.Net > Forums > Unix > process monitor script (re-post)

process monitor script (re-post)

Reply to Message Icon

Original Message
Name: Br1an
Date: September 29, 2002 at 05:27:36 Pacific
Subject: process monitor script (re-post)
OS: Unix
CPU/Ram: 256
Comment:

Hi,
does anyone know how to write a script (prob using pgrep/pkill) to kill processes
that making more than 5 copies of ITSELF ??
Thanks
PS: this is quite urgent, please help. I got
one reply yesterday, but i'm still in doubt.
Please gimme a hand. My manager gonna ask for it soon. Thanks


Report Offensive Message For Removal

Response Number 1
Name: David Perry
Date: September 30, 2002 at 04:06:13 Pacific
Subject: process monitor script (re-post)
Reply: (edit)

To answer your first question, yes.
The following works with solaris

#!/bin/ksh
if [ $# -gt 0 ]; then
process_name=$1
ps_count=`ps -ef | grep -v 'grep' | grep -v 'kill' | grep -i -c $process_name`
echo "Process count: $ps_count"
if [ $ps_count -le 5 ] ; then
exit 0
fi
set -A array_name `ps -ef | grep -i $process_name | grep -v 'grep' | grep -v 'kill' | awk '{print $2}' | sort -u`
print "ps -ef | grep -i $process_name | grep -v 'grep' | grep -v 'kill' | awk '{print \$2 \$8}' | sort -u -n"

print "${array_name[*]}"
kill_count=0
while [ $kill_count -lt $ps_count ]
do
kill -9 ${array_name[$kill_count]}
((kill_count=kill_count+1))
done

else
print "Usage: $0 process_name"
print ""
fi


Report Offensive Follow Up For Removal

Response Number 2
Name: Br1an
Date: September 30, 2002 at 06:09:04 Pacific
Subject: process monitor script (re-post)
Reply: (edit)

Thanks a lot..however, what if i don't know
the name of the process, then can I do a
pgrep -ef first to take note which process
is having more than 5 copies of itself, then
execute the procedure above, then do a pgrep
-ef again to check (this should be done
inside a loop) until no more processes are
having more than 5 copies ?
however, i know that every one is busy,
struggling with their own bosses P:), so
this is a *HUGE* help for me, thanks a lot
David. If you got some spare time, then any
further discuss, hint about this topic is
more than welcome.
Cheers


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: process monitor script (re-post)

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software