Operating System - HP-UX
1751707 Members
5365 Online
108781 Solutions
New Discussion юеВ

Anyone got a script that does something similar ?

 
SOLVED
Go to solution
Al_19
New Member

Anyone got a script that does something similar ?

hi,

I'm looking for a script that basically monitors a process or pid say every 2 mins and checks it's VSIZ values. Once VSIZ gets to XXX Mb, the script forces a "kill -6" on the process or pid and the restarts the process over again ....

any help / suggestions/ pitfalls to look out for appreciated.

7 REPLIES 7
harry d brown jr
Honored Contributor

Re: Anyone got a script that does something similar ?

If you have glance installed, you can use the alarm mechanism to do it.

live free or die
harry
Live Free or Die
Volker Borowski
Honored Contributor

Re: Anyone got a script that does something similar ?

Not sure if this is what you want,
I did not find a way to get VSIZ colum to "ps"
but try this:


LIMIT=1000
while true
do
PID=`cat pid_file`
SZ=`ps -lp $PID | tail -n 1 | awk '{ print $10 }'`
if [ $SZ -gt $LIMIT ]
then
kill -6 $PID
fi
sleep 120
done

Volker
Al_19
New Member

Re: Anyone got a script that does something similar ?

Harry 10 pts on offer is you could elaborate a bit ... glance looks interesting do you know the metrics I'd need to use ? I did have a scour through them but gpm is newto me.

Volker, I'll give it a go .....
James R. Ferguson
Acclaimed Contributor

Re: Anyone got a script that does something similar ?

Hi:

Use the XPG4 (UNIX95) option of the 'ps' command to find your 'vsz' [kilobytes of physical pages comprising core image].

You can sample the environment as follows:

# UNIX95= ps -e -o pid -o user -o vsz -o comm | k3nr

Note the blank character after the UNIX95 variable and before the 'ps' command. This sets the UNIX95 environmental variable only for the command line. See the man pages for 'ps' for more information.

The output of the above will produce a sorted list in descending 'vsz' size, each line consisting of the 'pid', the 'user', the 'vsz' and the 'comm'and representing the process.

Regards!

...JRF...
Mark Greene_1
Honored Contributor
Solution

Re: Anyone got a script that does something similar ?

try this, not tested except for the ps statement, caveat emptor and all that:

#!/bin/ksh
# monitor - monitor's a process core size
# run as: monitor pid#
###

# setup #
MAX_CORE=1024 # max size of core image
PID=$1
if [ $PID = '' ]; then
exit 1 # no pid given
fi
CMD="UNIX95= ps -p 8964 -o vsz|tail -1"

# process #

CRNT_CORE=`$CMD`
while [ $"CRNT_CORE" -ne "" ]; do

if [ $"CRNT_CORE" -gt $"MAX_CORE" ]; then
kill -6 $PID
exit 0
fi
sleep 120 # wait 120 seconds
CRNT_CORE=`$CMD` # get new value for next pass

done
exit 0
the future will be a lot like now, only later
Al_19
New Member

Re: Anyone got a script that does something similar ?

Thanks all I have enough to get my teeth into for now !
harry d brown jr
Honored Contributor

Re: Anyone got a script that does something similar ?

Al,

In /opt/perf/examples/adviser/ there are a few examples, here is one I built and tested, of course you should replace the "exec" line with a script passing the pid that will kill the process and restart the job:

VSSthreshold = 10000
PROCESS loop
{if PROC_MEM_VIRT > VSSthreshold
then
{
exec "echo bad process ", PROC_PROC_ID, " vmem is ", PROC_MEM_VIRT

}
}


note that PROC_MEM_VIRT is in K-bytes, so 10000 is 10mb (10,000,000)

live free or die
harry
Live Free or Die