Calculate %Cpu

view full story

http://www.unix.com – Hi. For an homework, I have to simulate some part of the PS function. By reading the doc I've been able to find most of it but I don't how I can get the %cpu for each PID. I've read on Internet that I have to do: (utime(t)-utim(t-1))/(cputime(t)-cputime(t-1)) where cputime is the sum of int in the file /proc/stat for the line cpu. and utime is find in /proc/pid/stat but it didn't work. How can i get it? PS: Sorry, for my english. (HowTos)