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

I would like to monitor one process's memory / cpu usage in real time. Similar to top but targeted at only one process, preferably with a history graph of some sort.

share|improve this question
What memory statistics do you want? There are lots of them. – vwduder Jan 13 '11 at 11:33
Memory usage over a given time frame, current usage, maximum usage, average. – Josh K Jan 13 '11 at 11:33
up vote 56 down vote accepted

On Linux, top actually supports focusing on a single process, although it naturally doesn't have a history graph:

top -p PID

This is also available on Mac OS X with a different syntax:

top -pid PID
share|improve this answer
And since you may not want to look up the PID every time, try something like top -p `pgrep -f /usr/bin/kvm`. – Stefan Lasiewski Aug 17 '10 at 3:33
I use Cacti to monitor some individual processes, but installing a full blown Cacti installation sounds too complex for the simple situation asked here. – Stefan Lasiewski Aug 17 '10 at 3:34
@Stefan: I'm assuming I would have to run that remotely? – Josh K Aug 17 '10 at 4:00
@Josh : Yes you would need to run Cacti (Which requires MySQL, Apache and few other packages) on another server. On most distros, it's pretty simple to install using Yum or apt-get. – Stefan Lasiewski Aug 17 '10 at 20:48
@Stefan if you want to to check remotly you can do ssh@remotehost 'top -p PID > ~hostname_pid.txt; exit'and – klerk May 13 '14 at 20:02

htop is a great replacement to top. It has... Colors! Simple keyboard shortcuts! Scroll the list using the arrow keys! Kill a process without leaving and without taking note of the PID! Mark multiple processes and kill them all!

Among all of the features, the manpage says you can press F to follow a process.

Really, you should try htop. I never started top again, after the first time I used htop.

Display a single process:

htop -p PID

share|improve this answer
+1 for htop. This is one of the first program I install on a new system. It makes my life much easier. The tree view is also very handy. – Barthelemy Nov 24 '10 at 12:22
top also has colors. Press z. – Tshepang Jan 12 '11 at 1:41
You're right! top has colors! Too bad its colors are quite useless, specially when compared to htop (which fades other users processes and highlights the program basename). – Denilson Sá Jan 12 '11 at 18:17
And htop -p PID will work too, just like the example given by @Michael Mrozek. – noisebleed Nov 25 '14 at 12:05
Then only reason to use top, is because htop is not available or can't be installed. That is why htop was created, to provide much more features. – lepe Apr 13 '15 at 2:55

I normally use following two :

  1. HP caliper : its very good tool for monitoring processes it you can check call graph and other low level information also. But please note its free only for personal use.

  2. daemontools : a collection of tools for managing UNIX services

share|improve this answer
I used daemontools for years. It's great as a supervisor/watchdog for other processes. How does it help you monitor CPU/memory usage for one process? – Stefan Lasiewski Aug 19 '10 at 4:05

To use that information on a script you can do this:


nTimes=10; # customize it
delay=0.1; # customize it
strCalc=`top -d $delay -b -n $nTimes -p $nPid \
  |grep $nPid \
  |sed -r -e "s;\s\s*; ;g" -e "s;^ *;;" \
  |cut -d' ' -f9 \
  |tr '\n' '+' \
  |sed -r -e "s;(.*)[+]$;\1;" -e "s/.*/scale=2;(&)\/$nTimes/"`;
nPercCpu=`echo "$strCalc" |bc -l`
echo $nPercCpu

use like: calcPercCpu.sh 1234 where 1234 is the pid

For the specified $nPid, it will measure the average of 10 snapshots of the cpu usage in a whole of 1 second (delay of 0.1s each * nTimes=10); that provides a good and fast accurate result of what is happening in the very moment.

Tweak the variables to your needs.

share|improve this answer

If you need the averages for a period of time of a specific process, try the accumulative -c option of top:

top -c a -pid PID

"-c a" found in top for Mac 10.8.5.

For Scientific Linux, the option is -S, that can be set interactively.

share|improve this answer
You'll likely want to add further details around which version(s) of top actually provide this feature. My version on Fedora 19 does not. Same too on Ubuntu 13.04. – slm May 12 '14 at 1:22
You're right!, I was so happy of having found something useful, I forgot I was in my mac at home. – Kieleth May 13 '14 at 19:34

If you know process name you can use

top -p $(pidof <process_name>)
share|improve this answer
That's pretty much what the accepted answer, from years ago, and its first comment say. – dhag Apr 29 '15 at 15:26

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.