Public domain
#!/bin/sh
# @(#)/usr/local/bin/mon, quick & dirty process monitor
# @(#)Bela Lubkin, June 1997 & December 2000
# @(#)Bob Stockler, December 2000
# @(#)Jean-Pierre Radley, December 2000
trap 'echo "$CN\c";trap 0;exit' 0 2 3 15
trap 'trap 0;exit' 1
N=`tput lines`
EL=`tput el` ED=`tput ed` CL=`tput clear` HO=`tput home`
CF=`tput civis` CN=`tput cnorm` F="%12.2f%3d$ED$HO"
echo "$CF$CL\c"
HDR="`ps -p1 -opid -opcpu -oc -oargs | head -1`"
while :
do
ps -e -opid= -opcpu= -oc= -oargs= |
sort -rn +1 |
awk -v H="$HDR" -v N="$N" -v E="$EL" -v F="$F" '
BEGIN{print H;N-=2}
$2>0||$3{print substr($0,1,79) E;P+=$2;C+=$3}
NR>=N{exit}
END{printf F,P,C}'
sleep ${1-1} # sleep time on script's command line (default 1 sec.)
done
BY: Bela Lubkin, Bob Stockler, Jean-Pierre Radley
TAG: cpu, trap, tput, awk, sort, bash-script, bash
DATE: 2009-04-25 00:19:57