Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
vmstat 1

Above will print virtual memory statistics each seconds. It will also show the CPU utilization for last second.

I have a web server at hand which runs httpd and MySQL. I need to find how much CPU httpd consumed in last second. Like vmstat particularly for httpd.

I tried this :

ps -e -o %mem,%cpu,cmd | grep mysql | awk '{memory+=$1;cpu+=$2} END {print memory,cpu}'

But it will show me the ratio of CPU used since the start of the process.

So, with above, if my process caused a spike and then went to sleep for long time, I wont know it. Its like windows process manager, which shows which process is using how much CPU. I hope I am making my question understandable. I will clarify if anything is missing.

share|improve this question
up vote 3 down vote accepted

You could use top -b -d 1 to achieve that for CPU usage. top displays process CPU usage relative to the last output.

share|improve this answer

cgroups has a whole accounting suite to play with and is lightweight.

https://www.kernel.org/doc/Documentation/cgroups/ https://www.kernel.org/doc/Documentation/cgroups/cpuacct.txt

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.