This script I use to snapshot the process table and add up the times each process has on the CPU. Sometimes a process is running more than one instance, so it totals up these duplicate processes. If a process, at the time of the snapshot, has not used any CPU, it will not be shown.

if [[ -d /tmp/proctsm ]];then
   rm -r /tmp/proctsm
   mkdir /tmp/proctsm
else
   mkdir /tmp/proctsm
fi
 
ps aux | sort -k3r | awk '{print $1,$3,$11}' > /tmp/pstable
cat /tmp/pstable | grep -v "COMMAND" | while read user cpu process
do
   procfile=/tmp/proctsm/$(echo $process | sed -e 's/\///g' -e 's/\[//g' -e 's/\]//g' -e 's/\://g' -e 's/\-//g').tsm
   echo $cpu >> $procfile
done
 
cd /tmp/proctsm
ls *.tsm | while read file
do
   sum=0.0
   cat $file | while read cpu
   do
      sum=$(echo "scale=2; ${sum}+${cpu}" | bc -l)
      echo $sum >> ${file}.sum
   done
done
 
ls *.sum | while read file
do
   cpu=tail -1 $file
   if [[ $cpu > 0 ]];then
      process=${file%%.*}
      echo "$process $cpu"
   fi
done
Private