Find Memory Or RAM And Swap Usage In Linux


RAM plays an important role in the performance of a system. So we should monitor this memory usage to troubleshoot system. free is the basic command to get details of RAM and swap usage.


Example :

# free
total used free shared buffers cached
Mem: 3059872 2842016 217856 0 33936 2012684
-/+ buffers/cache: 795396 2264476
Swap: 2000052 67672 1932380

When you see its giving total size, used and free size in bytes. If you want to see in MB specify

-m option in free

#free -m

Example :

# free -m
total used free shared buffers cached
Mem: 2988 2784 203 0 33 1974
-/+ buffers/cache: 776 2211
Swap: 1953 66 1887

Any other commands to check RAM?
The answer for this is yes.
1. Use proc file system to get detailed RAM usage of the system.

#cat /proc/meminfo

2. Use top command to see RAM usage

So with top too you can see RAM usage live.

  • Like the post? Please Subscribe to free RSS feed to get updates
  • How To Find And Remove Core Files In Linux?


    What is a"Core file" ? Ans : A core file is created when a program is crashed/stoped abnormally due to some bug. This will be huge size which contains all the memory info, crash info which is used for programmers to debug the issue and find a solution or patch to that bug.

    Why we system administrators are interested in that core files?
    Ans : This is because of their size. As we do monitoring of systems on daily basis but suddenly your disk is full one day when you came to office, you are total blank thinking how come disk is full though there is no much user activity etc. So core files are one reason which will eat up our disk. Which you have to check for when sudden disk activity is observed.

    How to find core files ?
    #find / -name core

    This find command will search entire filesystem for core files.. once you find them use rm command to remove those files..
    #rm -rf core

    So how it got its name?
    A core dump file gets its name from an old memory technology using tiny magnetic cores for storage.

  • Like the post? Please Subscribe to free RSS feed to get updates
  • How To Kill Defunct Or Zombie Process?


    A "defunct" processes is also known as a "zombie" processes. A Zombie process is referred as dead process which is receding on your system thought its completed executing. In one shot we can say its a dead processes. This process will be in your process table and consuming your memory. Having more defunct process will consume your memory which intern slows your system. We have to kill the defunct process in order to free RAM and make system stable.

    Why defunct process are created?
    Ans :
    When ever a process ends all the memory used by that process are cleared and assigned to new process but due to programming errors/bugs some processes are still left in process table. These are created when there is no proper communication between parent process and child process.

    Some FAQ?

    1. How to find a defunct process?
    And : Grep defunct value in ps -ef output
    #ps -ef grep defunct

    2. How can i kill a defunct process?
    And :
    Just use kill command
    #kill defunct-pid

    3. Still not able to kill?

    Ans : Then use kill -9 to force kill that process
    #kill -9 defunct-pid

    4. Still have an issue in killing it?

    Ans : Then try to kill its parent id and then defunct.
    #kill parent-id-of-defunct-pid

    #kill -9 parent-id-of-defunct-pid

    5. Still having defunct?

    Ans : If you still find defunct process eating up RAM then last and final solution is to reboot your machine.

    6.What is orphan process?
    Ans : An orphan process is said to be a process which runs though parent process is terminated, these process do not know what to do and when to terminate.

    7. What is difference between orphan and defunct processes?
    Ans :
    A defunct process is a dead process where there is no execution happening where as orphan process is a live process which is still in execution state but don't have parent process

    I am having a system which daily creates defunct process, I cannot sit and kill these process on daily basis.

    How to get rid of this problem?
    Ans : Just write a shell script to grep defunct process and kill them by putting this script in corntab.

  • Like the post? Please Subscribe to free RSS feed to get updates
  • Hot To See Memory(RAM) Used By An Application Or Service?


    Some times its required for us to know what is the RAM utilized by an application. Suppose in your machine Apache service or Mysql service is consuming up all your RAM. So how to check it? Is there any direct command to accomplish this? The answer to this is no. We have to use two commands to accomplish this. Here is the way to see what is the ram utilized by a particular Application.

    To see all the process run by a particular application
    #pgrep application-name

    Example(in Ubuntu)
    #pgrep apache

    To see all the memory used by a process
    #pmap pid-of-that-application

    Example :
    # pmap 1946
    1946: /usr/sbin/apache2 -k start
    00110000 28K r-x-- /lib/tls/i686/cmov/
    00117000 4K r---- /lib/tls/i686/cmov/
    00118000 4K rw--- /lib/tls/i686/cmov/
    00119000 8K r-x-- /usr/lib/apache2/modules/
    0011b000 4K r---- /usr/lib/apache2/modules/
    0011c000 4K rw--- /usr/lib/apache2/modules/
    0011d000 8K r-x-- /usr/lib/apache2/modules/
    0011f000 4K r---- /usr/lib/apache2/modules/
    00120000 4K rw--- /usr/lib/apache2/modules/
    00121000 16K r-x-- /usr/lib/apache2/modules/
    00125000 4K r---- /usr/lib/apache2/modules/
    00126000 4K rw--- /usr/lib/apache2/modules/
    00129000 76K r-x-- /lib/tls/i686/cmov/
    0013c000 4K r---- /lib/tls/i686/cmov/
    0013d000 4K rw--- /lib/tls/i686/cmov/
    0013e000 8K rw--- [ anon ]
    00140000 32K r-x-- /usr/lib/apache2/modules/
    00148000 4K r---- /usr/lib/apache2/modules/
    00149000 4K rw--- /usr/lib/apache2/modules/
    0014a000 80K r-x-- /lib/
    0015e000 4K r---- /lib/
    0015f000 4K rw--- /lib/
    00160000 8K r-x-- /lib/
    00162000 4K r---- /lib/
    00163000 4K rw--- /lib/
    00164000 8K r-x-- /lib/
    00166000 4K r---- /lib/
    00167000 4K rw--- /lib/
    00168000 24K r-x-- /usr/lib/php5/20060613+lfs/
    0016e000 4K r---- /usr/lib/php5/20060613+lfs/
    0016f000 4K rw--- /usr/lib/php5/20060613+lfs/
    00171000 24K r-x-- /lib/tls/i686/cmov/
    00177000 4K r---- /lib/tls/i686/cmov/
    00178000 4K rw--- /lib/tls/i686/cmov/
    00179000 36K r-x-- /lib/tls/i686/cmov/
    00182000 4K r---- /lib/tls/i686/cmov/
    00183000 4K rw--- /lib/tls/i686/cmov/
    00184000 144K r-x-- /lib/tls/i686/cmov/
    001a8000 4K r---- /lib/tls/i686/cmov/
    001a9000 4K rw--- /lib/tls/i686/cmov/
    001aa000 40K r-x-- /usr/lib/php5/20060613+lfs/
    001b4000 4K r---- /usr/lib/php5/20060613+lfs/
    001b5000 4K rw--- /usr/lib/php5/20060613+lfs/
    001bf000 28K r-x-- /usr/lib/apache2/modules/
    001c6000 4K r---- /usr/lib/apache2/modules/
    001c7000 4K rw--- /usr/lib/apache2/modules/
    001c8000 92K r-x-- /usr/lib/php5/20060613+lfs/
    001df000 4K r---- /usr/lib/php5/20060613+lfs/
    001e0000 8K rw--- /usr/lib/php5/20060613+lfs/
    001e4000 4K r-x-- [ anon ]
    001f0000 188K r-x-- /lib/
    0021f000 4K r---- /lib/
    00220000 4K rw--- /lib/
    00221000 76K r-x-- /usr/lib/php5/20060613+lfs/
    00234000 4K r---- /usr/lib/php5/20060613+lfs/
    00235000 8K rw--- /usr/lib/php5/20060613+lfs/
    00241000 4K r-x-- /usr/lib/apache2/modules/
    00242000 4K ----- /usr/lib/apache2/modules/
    00243000 4K r---- /usr/lib/apache2/modules/
    00244000 4K rw--- /usr/lib/apache2/modules/
    00246000 64K r-x-- /lib/tls/i686/cmov/
    00256000 4K r---- /lib/tls/i686/cmov/
    00257000 4K rw--- /lib/tls/i686/cmov/
    00258000 8K rw--- [ anon ]
    00260000 36K r-x-- /lib/tls/i686/cmov/
    00269000 4K r---- /lib/tls/i686/cmov/
    0026a000 4K rw--- /lib/tls/i686/cmov/
    0026b000 156K rw--- [ anon ]
    00292000 112K r-x-- /lib/
    002ae000 4K r---- /lib/
    002af000 4K rw--- /lib/
    002b9000 12K r-x-- /lib/
    002bc000 4K r---- /lib/
    002bd000 4K rw--- /lib/
    002be000 260K r-x-- /lib/i686/cmov/
    002ff000 4K ----- /lib/i686/cmov/
    00300000 4K r---- /lib/i686/cmov/
    00301000 12K rw--- /lib/i686/cmov/
    00304000 152K r-x-- /usr/lib/
    0032a000 4K ----- /usr/lib/
    0032b000 4K r---- /usr/lib/
    0032c000 4K rw--- /usr/lib/
    00349000 144K r-x-- /lib/
    0036d000 8K r---- /lib/
    0036f000 4K rw--- /lib/
    00385000 4K r-x-- /usr/lib/apache2/modules/
    00386000 4K r---- /usr/lib/apache2/modules/
    00387000 4K rw--- /usr/lib/apache2/modules/
    003ec000 160K r-x-- /usr/lib/
    00414000 4K r---- /usr/lib/
    00415000 4K rw--- /usr/lib/
    00416000 636K r-x-- /usr/lib/
    004b5000 4K ----- /usr/lib/
    004b6000 20K r---- /usr/lib/
    004bb000 4K rw--- /usr/lib/
    004e3000 8K r-x-- /usr/lib/apache2/modules/
    004e5000 4K ----- /usr/lib/apache2/modules/
    004e6000 4K r---- /usr/lib/apache2/modules/
    004e7000 4K rw--- /usr/lib/apache2/modules/
    00501000 8K r-x-- /usr/lib/apache2/modules/
    00503000 4K r---- /usr/lib/apache2/modules/
    00504000 4K rw--- /usr/lib/apache2/modules/
    0060f000 8K r-x-- /usr/lib/apache2/modules/
    00611000 4K r---- /usr/lib/apache2/modules/
    00612000 4K rw--- /usr/lib/apache2/modules/
    006f6000 4K r-x-- /usr/lib/apache2/modules/
    006f7000 4K r---- /usr/lib/apache2/modules/
    006f8000 4K rw--- /usr/lib/apache2/modules/
    006f9000 1428K r-x-- /usr/lib/
    0085e000 8K r---- /usr/lib/
    00860000 4K rw--- /usr/lib/
    00907000 20K r-x-- /usr/lib/apache2/modules/
    0090c000 4K r---- /usr/lib/apache2/modules/
    0090d000 4K rw--- /usr/lib/apache2/modules/
    00950000 4K r-x-- /usr/lib/apache2/modules/
    00951000 4K r---- /usr/lib/apache2/modules/
    00952000 4K rw--- /usr/lib/apache2/modules/
    0099e000 4K r-x-- /usr/lib/apache2/modules/
    0099f000 4K r---- /usr/lib/apache2/modules/
    009a0000 4K rw--- /usr/lib/apache2/modules/
    00a13000 372K r-x-- /usr/lib/apache2/mpm-prefork/apache2
    00a71000 8K r---- /usr/lib/apache2/mpm-prefork/apache2
    00a73000 8K rw--- /usr/lib/apache2/mpm-prefork/apache2
    00a75000 12K rw--- [ anon ]
    00ad5000 24K r-x-- /usr/lib/
    00adb000 4K r---- /usr/lib/
    00adc000 4K rw--- /usr/lib/
    00b28000 132K r-x-- /usr/lib/
    00b49000 4K r---- /usr/lib/
    00b4a000 4K rw--- /usr/lib/
    00b66000 64K r-x-- /lib/
    00b76000 4K r---- /lib/
    00b77000 4K rw--- /lib/
    00b90000 16K r-x-- /usr/lib/apache2/modules/
    00b94000 4K r---- /usr/lib/apache2/modules/
    00b95000 4K rw--- /usr/lib/apache2/modules/
    00ba6000 164K r-x-- /usr/lib/
    00bcf000 4K r---- /usr/lib/
    00bd0000 4K rw--- /usr/lib/
    00bf5000 12K r-x-- /usr/lib/apache2/modules/
    00bf8000 4K r---- /usr/lib/apache2/modules/
    00bf9000 4K rw--- /usr/lib/apache2/modules/
    00c7e000 40K r-x-- /lib/tls/i686/cmov/
    00c88000 4K r---- /lib/tls/i686/cmov/
    00c89000 4K rw--- /lib/tls/i686/cmov/
    00ce9000 1272K r-x-- /lib/tls/i686/cmov/
    00e27000 8K r---- /lib/tls/i686/cmov/
    00e29000 4K rw--- /lib/tls/i686/cmov/
    00e2a000 12K rw--- [ anon ]
    00e67000 84K r-x-- /lib/tls/i686/cmov/
    00e7c000 4K r---- /lib/tls/i686/cmov/
    00e7d000 4K rw--- /lib/tls/i686/cmov/
    00e7e000 8K rw--- [ anon ]
    00f69000 108K r-x-- /lib/
    00f84000 4K r---- /lib/
    00f85000 4K rw--- /lib/
    00f9d000 8K r-x-- /lib/tls/i686/cmov/
    00f9f000 4K r---- /lib/tls/i686/cmov/
    00fa0000 4K rw--- /lib/tls/i686/cmov/
    00fa1000 5036K r-x-- /usr/lib/apache2/modules/
    0148c000 4K ----- /usr/lib/apache2/modules/
    0148d000 68K r---- /usr/lib/apache2/modules/
    0149e000 148K rw--- /usr/lib/apache2/modules/
    014c3000 20K rw--- [ anon ]
    01cc1000 1204K r-x-- /lib/i686/cmov/
    01dee000 32K r---- /lib/i686/cmov/
    01df6000 52K rw--- /lib/i686/cmov/
    01e03000 16K rw--- [ anon ]
    03087000 1716K r-x-- /usr/lib/
    03234000 12K r---- /usr/lib/
    03237000 276K rw--- /usr/lib/
    0327c000 4K rw--- [ anon ]
    06147000 1160K r-x-- /usr/lib/
    06269000 4K ----- /usr/lib/
    0626a000 16K r---- /usr/lib/
    0626e000 4K rw--- /usr/lib/
    0626f000 4K rw--- [ anon ]
    21436000 2820K rw--- [ anon ]
    b6d8a000 4K ----- [ anon ]
    b6d8b000 10240K rw--- [ anon ]
    b77cc000 16K rw--- [ anon ]
    b77d0000 64K rw-s- /dev/zero (deleted)
    b77e0000 8K rw--- [ anon ]
    bfc89000 84K rw--- [ stack ]
    total 29964K
    So you have to run this command on all the process of apache application. If you see the last line its showing total RAM utilized by this PID. Which is ~30MB. Which is nothing but total RAM used by this PID

    Suppose if you want to see all the memory(RAM), files opend by apache use below command
    #pmap `pgrep apache`

    If you execute above command it will give pages and pages of information which you donot require, to get answer in presized way. Just grep last line with "total".

    Example :
    # pmap `pgrep apache` | grep total
    total 29964K
    total 29964K
    total 29964K
    total 29964K
    total 29964K
    total 29964K
    total 29964K

    Please share your thoughts if you have more better options to check RAM utilization by an application:-)

  • Like the post? Please Subscribe to free RSS feed to get updates
  • How To See Total Processes Are Running, Files Opened, Memory Used By An User?


    To see all the process run by a perticular user
    #ps -u username u

    #ps -u rajesh u


    To see all the files opened by user
    #lsof grep username

    #lsof grep rajesh

    To see memory used by a perticular user
    #ps -u username u awk '{print $2}'

    ps -u krishna u awk '{print $2}'

    Now you will get all the PID's run by user Krishna. So try to get memory usage by using pmap command.

  • Like the post? Please Subscribe to free RSS feed to get updates
  • How To See What Processes Are Running On Your System?


    Q. I know the subject is not quite what I want to know, but there is a command to list running processes and I can't remember what it is? There are many commands to accomplish this. Here is the list.

    To see all the process running on a system
    #ps -A

    Example output :

    1 ? 00:00:01 init
    2 ? 00:00:00 kthreadd
    3 ? 00:00:00 migration/0
    4 ? 00:00:00 ksoftirqd/0
    5 ? 00:00:00 watchdog/0
    6 ? 00:00:00 migration/1
    7 ? 00:00:01 ksoftirqd/1
    8 ? 00:00:00 watchdog/1
    9 ? 00:00:00 events/0
    10 ? 00:00:00 events/1

    To see all the process running on a system with some more information about the executed files location.
    #ps -ef

    Example output :

    root 1 0 0 20:42 ? 00:00:01 /sbin/init
    root 2 0 0 20:42 ? 00:00:00 [kthreadd]
    root 3 2 0 20:42 ? 00:00:00 [migration/0]
    root 4 2 0 20:42 ? 00:00:00 [ksoftirqd/0]
    root 5 2 0 20:42 ? 00:00:00 [watchdog/0]
    root 6 2 0 20:42 ? 00:00:00 [migration/1]
    root 7 2 0 20:42 ? 00:00:01 [ksoftirqd/1]

    To see all the process in a "tree structure"

    Example output :

    │ └─{NetworkManager}

    To see all the files opened

    hald-addo 2384 root txt REG 8,8 22236 135896 /usr/lib/hal/hald-addon-storage
    hald-addo 2384 root mem REG 8,8 117152 5754 /usr/lib/
    hald-addo 2384 root mem REG 8,8 30684 2537 /lib/tls/i686/cmov/
    hald-addo 2384 root mem REG 8,8 743912 1332 /lib/
    hald-addo 2384 root mem REG 8,8 1319364 2507 /lib/tls/i686/cmov/
    hald-addo 2384 root mem REG 8,8 247788 5986 /usr/lib/
    hald-addo 2384 root mem REG 8,8 116920 2533 /lib/tls/i686/cmov/
    hald-addo 2384 root mem REG 8,8 113320 1278 /lib/
    hald-addo 2384 root mem REG 8,8 227000 1314 /lib/
    hald-addo 2384 root mem REG 8,8 193860 1383 /lib/
    hald-addo 2384 root mem REG 8,8 71144 6123 /usr/lib/

    To see the process in dynamic way



    My favorate one is htop. But by default its not there. You have to install it.

  • Like the post? Please Subscribe to free RSS feed to get updates
  • Archive

    Translate this page


    The Linux Juggernaut | Copyright 2006-2009 Surendra Kumar Anne | Surendra's Home Page | Give us feedback how we are doing, Click here