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.

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
7 comments… add one
  • Mahesh Dec 5, 2007 @ 13:05

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

    • boopathi Nov 2, 2010 @ 5:05

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

      • obsolesced Sep 6, 2016 @ 9:45

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

  • Tim Jun 26, 2008 @ 14:45

    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 Nov 30, 2011 @ 6:49

    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 Jul 24, 2012 @ 11:52

    atop and htop will never work on fedora

  • Sorin DANULESCU Aug 6, 2012 @ 21:58

    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 Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.