#!/bin/sh
# To calibrate run this while doing a capture, then change the if
# statement so it detects about 1/2 of the average CPU used.
monitor(){
	echo monitoring cpu...
	nerr=0
	old=`head -1 /proc/stat`
	while sleep 1
	do
	new=`head -1 /proc/stat`
	{
	    echo $old
	    echo $new
	} | awk '
	BEGIN { cpu=0 } 
	{
	    if(cpu==0) {
	        cpu=$2
	    } else {
	        if($2-cpu<50) print "1 " $2-cpu
            else print "0 " $2-cpu
	    }
	}'
	old=$new
	done
}
monitor
