ps -elf AND grep for changes

Hoping theres something already out there like this.

I have a list of proccesses who's "ps -elf" (field 10) values I need to continuously monitor and if the values of field 10 start to signiciantly increase (double, triple) then do something. The field 10 is the "memory size" field.

(these are constant process names)

process1
process2
process3
foreach proccx ( process1 process2 process3 )
  initvar1,2,3 = ps -elf |grep $proccx |awk '{print $10}'
end

So now I would have 3 initial vars, (initvar1, initvar2, and initvar3)

Now enter some kind of a monitoring loop "for each" of the processes.

foreach proccx ( process1 process2 process3 )
  set curvar1,2,3 = ps -elf |grep process1 |awk {print $10}'
  if $curvar1 > $initvar1 * 2 , do something.
end

sleep 5
end

cshell or bash on solaris v10. The real problem I have found is variable "passing"

You could try this in bash:

#!/bin/bash
while true
do 
    while read pid mem
    do
       [ -z "${orig[pid]}" ] && orig[pid]=$mem
       if [ $((orig[pid]*2)) -lt $mem ]
       then
           echo "$pid has grown from ${orig[pid]} to $mem"
       fi
    done  < <(ps -elf | awk '/[p]rocess1|[p]rocess2|[p]rocess3/{print $4 " " $10}')
    sleep 5
done

Things to think about:
process ends - should really be removed from orig array, this one isn't a big deal.

1 Like

now wheres that thank-you button?

What operating system are you on? Most have built in monitoring alerts for such things.

the above script by Chubler_XL works great. The only issue is that the process names (process1, process2, process3) are not always very unique, and often just using the unique part of the name will reference multiple processes. I'd rather generate up a list of PIDs and then use this list for monitoring. I'm trying to figure out a way to do this based on just the PID

Also,
If there is an Solaris OS utility for this type of monitoring please let me know.
Thank you all so much!
:stuck_out_tongue: