Linux find out what process are eating all memory and time allocated to process

Posted on in Categories last updated August 31, 2006

Q. How do I find out what process are eating up all my memory. Is it possible to find out how long that memory has been allocated to particular process? How do I kill that process to free up memory?

A. You need to use the top command which provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel.

Simply type top command:
# top

top command will tell you the percentage of physical memory a particular process is using at any given time. As far as I know, there is no easy way that can tell how long that memory has been allocated.

You can also use ps command to get more information about process.
# ps aux | less

To kill process use kill command under Linux. Read man page of top and ls for more information.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

7 comment

  1. I recommend using `htop’ instead of top to monitor processes. It’s much friendlier and easy to use, and allows you to do more. (It’s colorized too!)

    It’s in the ubuntu repositories, I imagine you can install it easily for debian as well.

  2. I prefer using atop.. which gives all the option network activity, disk activity and many more you can check in the man page of it

    I dont know abt redhat and fedora but its there in ubuntu and debian repo

  3. what about this command:

    ps axu | awk '{print $2, $3, $4, $11}' | head -1 && ps axu | awk '{print $2, $3, $4, $11}' | sort -k3 -nr |head -5

    The result is here

    PID %CPU %MEM COMMAND
    2222 3.2 3.8 /usr/lib/firefox/firefox
    1937 0.2 1.5 /home/sorin/.dropbox-dist/dropbox
    1073 3.8 1.0 /usr/bin/X
    2407 0.2 0.9 pidgin
    4105 1.5 0.8 /usr/lib/firefox/plugin-container
    

    I see the 5 processes which consume most of the memory.
    If I want to see the CPU, then I sort after second column => sort -k2

    ps axu | awk '{print $2, $3, $4, $11}' | head -1 && ps axu | awk '{print $2, $3, $4, $11}' | sort -k2 -nr |head -5

    outputs:

    PID %CPU %MEM COMMAND
    3448 16.9 0.2 rsync
    1073 3.7 1.0 /usr/bin/X
    2222 3.2 3.7 /usr/lib/firefox/firefox
    830 2.5 0.5 /sbin/mount.ntfs
    4105 1.4 0.6 /usr/lib/firefox/plugin-container
    

Leave a Comment