Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#!/bin/ksh
#
# Find processes that are hogging CPU.
#
# Criteria: CPU % >= 95/(number of processors) for two subsequent polls and
# elapsed time of more than 24 hours.
#
# Default threshold of 95 can by overridden using first parameter.
PROCS=$(/usr/sbin/psrinfo | grep on-line | wc -l)
RECIPIENTS=someone@somewhere.com
HOST=$(uname -n)
OUTPUT=/tmp/$(basename $0).$$
PIDS=/tmp/$(basename $0).pids
PREVPIDS=/tmp/$(basename $0).pids.prev
THRESHOLD=${1:-95}
touch ${PIDS} ${PREVPIDS}
ps -eo pid,pcpu,stime,etime,time,comm | nawk \
-v PROCS="${PROCS}" \
-v PIDS=${PIDS} \
-v PREVPIDS=${PREVPIDS} '
BEGIN {
THRESHOLD='${THRESHOLD}' / PROCS
getline
print
}
# If pcpu > THRESHOLD and elapsed time contains a "-" and two ":"s
# (i.e. more than 24 hours).
($2 >= THRESHOLD) && $4 ~ /-[0-9]*:[0-9]*:/ && $6 == "f45runw" {
HOG=$0
HOGPID=$1
while (getline < PREVPIDS) {
# Only display if was also hogging in previous run.
if ($1 == HOGPID) { print HOG }
}
close(PREVPIDS)
print HOGPID >> PIDS
}
' > ${OUTPUT} 2>&1
kill $(nawk '$1 ~ /[0-9]/ { print $1 }' ${OUTPUT})
echo "\n--\nOutput produced by $0" >> ${OUTPUT}
if [[ $(wc -l < ${OUTPUT}) -gt 4 ]]
then
mailx -s "Forms server processes killed on $HOST" ${RECIPIENTS} < ${OUTPUT}
fi
rm ${OUTPUT}
mv ${PIDS} ${PREVPIDS}