≡ Menu

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

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.

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 7 comments… add one }
  • Mahesh December 5, 2007, 1:05 pm

    i want to find the process execution time in LINUX???

    • boopathi November 2, 2010, 5:05 am

      time(command) | grep user|cut -f 2

      • obsolesced September 6, 2016, 9:45 am

        My time command writes to stderr instead of stdout, so I had to use (time command) 2>&1 | grep user

  • Tim June 26, 2008, 2:45 pm

    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.

  • Ashish Jaiswal November 30, 2011, 6:49 am

    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

  • Pradeep H N July 24, 2012, 11:52 am

    atop and htop will never work on fedora

  • Sorin DANULESCU August 6, 2012, 9:58 pm

    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

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: