I just had to add my version, heavily based on the elegant perl one-liner by @andor (beautiful perl code!)
- time : total CPU time since beginning (? or some computation of it, that is decayed if cpu usage goes down? I am not sure.... a high number signals a cpu intensive process, though)
- etime: total time elapsed since the process started
- the 2 ways for tail : on linux :
tail +2
doesn't work. On solaris, tail -n +2
doesn't work. So I try both to be sure.
Here is how to compute the times and also sort your processes by their mean CPU usage over time
ps -eo pid,comm,etime,time | { tail +2 2>/dev/null || tail -n +2 ;} | perl -ane '
@e=reverse split(/[:-]/,$F[2]); $se=$e[0]+$e[1]*60+$e[2]*3600+$e[3]*86400;
@t=reverse split(/[:-]/,$F[3]); $st=$t[0]+$t[1]*60+$t[2]*3600+$t[4]*86400;
if ( $se == 0 ) { $pct=0 ; } else { $pct=$st/$se ;};
printf "%s\t%s\t%s(%sseconds)\t%s(%sseconds)\t%.4f%%\n",$F[0],$F[1],$F[2],$se,$F[3],$st,$pct*100;
' | sort -k5,5n