rendered paste body#!/bin/shPS=/bin/psSLEEP=/bin/sleepKILL=/bin/killLOGGER=/usr/bin/loggerTAG=rss-watchdogusage(){ echo "$0 -p <pid> -k <kilobytes> [-w <secs>] [-s <signalname>]" echo " Defaults: -w 5 -s SIGTERM" exit 0}secs=5signame=SIGTERMwhile getopts p:k:w:s:? o; do case $o in p) pid=$OPTARG;; k) kb=$OPTARG;; w) secs=$OPTARG;; s) signame=$OPTARG;; ?) usage;; esacdoneif [ -z "$pid" -o -z "$kb" ]; then usagefi$LOGGER -t $TAG "Starting (pid=$pid rss=$kb wait=$secs sig=$signame)"while true; do rss=$($PS -p $pid -o rss=) if [ -z "$rss" ]; then $LOGGER -t $TAG "Exiting (pid=%pid vanished)" break fi if [ $rss -gt $kb ]; then $LOGGER -t $TAG "Killing (pid=$pid rss=$rss>$kb sig=$signame)" $KILL -s $signame $pid fi $SLEEP $secsdone