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

by on August 31, 2006 · 6 comments· LAST UPDATED August 31, 2006

in

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.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 6 comments… read them below or add one }

1 Mahesh December 5, 2007 at 1:05 pm

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

Reply

2 boopathi November 2, 2010 at 5:05 am

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

Reply

3 Tim June 26, 2008 at 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.

Reply

4 Ashish Jaiswal November 30, 2011 at 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

Reply

5 Pradeep H N July 24, 2012 at 11:52 am

atop and htop will never work on fedora

Reply

6 Sorin DANULESCU August 6, 2012 at 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

Reply

Leave a Comment

Tagged as:

Previous Faq:

Next Faq: