Find Memory Or RAM And Swap Usage In Linux

0 comments

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.

#free

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?

    0 comments

    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?

    1 comments

    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
    Then

    #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?

    0 comments

    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
    1946
    1951
    1952
    1954
    1955
    1957
    2894

    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/librt-2.10.1.so
    00117000 4K r---- /lib/tls/i686/cmov/librt-2.10.1.so
    00118000 4K rw--- /lib/tls/i686/cmov/librt-2.10.1.so
    00119000 8K r-x-- /usr/lib/apache2/modules/mod_auth_basic.so
    0011b000 4K r---- /usr/lib/apache2/modules/mod_auth_basic.so
    0011c000 4K rw--- /usr/lib/apache2/modules/mod_auth_basic.so
    0011d000 8K r-x-- /usr/lib/apache2/modules/mod_authz_groupfile.so
    0011f000 4K r---- /usr/lib/apache2/modules/mod_authz_groupfile.so
    00120000 4K rw--- /usr/lib/apache2/modules/mod_authz_groupfile.so
    00121000 16K r-x-- /usr/lib/apache2/modules/mod_deflate.so
    00125000 4K r---- /usr/lib/apache2/modules/mod_deflate.so
    00126000 4K rw--- /usr/lib/apache2/modules/mod_deflate.so
    00129000 76K r-x-- /lib/tls/i686/cmov/libnsl-2.10.1.so
    0013c000 4K r---- /lib/tls/i686/cmov/libnsl-2.10.1.so
    0013d000 4K rw--- /lib/tls/i686/cmov/libnsl-2.10.1.so
    0013e000 8K rw--- [ anon ]
    00140000 32K r-x-- /usr/lib/apache2/modules/mod_autoindex.so
    00148000 4K r---- /usr/lib/apache2/modules/mod_autoindex.so
    00149000 4K rw--- /usr/lib/apache2/modules/mod_autoindex.so
    0014a000 80K r-x-- /lib/libz.so.1.2.3.3
    0015e000 4K r---- /lib/libz.so.1.2.3.3
    0015f000 4K rw--- /lib/libz.so.1.2.3.3
    00160000 8K r-x-- /lib/libcom_err.so.2.1
    00162000 4K r---- /lib/libcom_err.so.2.1
    00163000 4K rw--- /lib/libcom_err.so.2.1
    00164000 8K r-x-- /lib/libkeyutils-1.2.so
    00166000 4K r---- /lib/libkeyutils-1.2.so
    00167000 4K rw--- /lib/libkeyutils-1.2.so
    00168000 24K r-x-- /usr/lib/php5/20060613+lfs/pdo_mysql.so
    0016e000 4K r---- /usr/lib/php5/20060613+lfs/pdo_mysql.so
    0016f000 4K rw--- /usr/lib/php5/20060613+lfs/pdo_mysql.so
    00171000 24K r-x-- /lib/tls/i686/cmov/libnss_compat-2.10.1.so
    00177000 4K r---- /lib/tls/i686/cmov/libnss_compat-2.10.1.so
    00178000 4K rw--- /lib/tls/i686/cmov/libnss_compat-2.10.1.so
    00179000 36K r-x-- /lib/tls/i686/cmov/libnss_nis-2.10.1.so
    00182000 4K r---- /lib/tls/i686/cmov/libnss_nis-2.10.1.so
    00183000 4K rw--- /lib/tls/i686/cmov/libnss_nis-2.10.1.so
    00184000 144K r-x-- /lib/tls/i686/cmov/libm-2.10.1.so
    001a8000 4K r---- /lib/tls/i686/cmov/libm-2.10.1.so
    001a9000 4K rw--- /lib/tls/i686/cmov/libm-2.10.1.so
    001aa000 40K r-x-- /usr/lib/php5/20060613+lfs/mysql.so
    001b4000 4K r---- /usr/lib/php5/20060613+lfs/mysql.so
    001b5000 4K rw--- /usr/lib/php5/20060613+lfs/mysql.so
    001bf000 28K r-x-- /usr/lib/apache2/modules/mod_negotiation.so
    001c6000 4K r---- /usr/lib/apache2/modules/mod_negotiation.so
    001c7000 4K rw--- /usr/lib/apache2/modules/mod_negotiation.so
    001c8000 92K r-x-- /usr/lib/php5/20060613+lfs/mysqli.so
    001df000 4K r---- /usr/lib/php5/20060613+lfs/mysqli.so
    001e0000 8K rw--- /usr/lib/php5/20060613+lfs/mysqli.so
    001e4000 4K r-x-- [ anon ]
    001f0000 188K r-x-- /lib/libpcre.so.3.12.1
    0021f000 4K r---- /lib/libpcre.so.3.12.1
    00220000 4K rw--- /lib/libpcre.so.3.12.1
    00221000 76K r-x-- /usr/lib/php5/20060613+lfs/pdo.so
    00234000 4K r---- /usr/lib/php5/20060613+lfs/pdo.so
    00235000 8K rw--- /usr/lib/php5/20060613+lfs/pdo.so
    00241000 4K r-x-- /usr/lib/apache2/modules/mod_dir.so
    00242000 4K ----- /usr/lib/apache2/modules/mod_dir.so
    00243000 4K r---- /usr/lib/apache2/modules/mod_dir.so
    00244000 4K rw--- /usr/lib/apache2/modules/mod_dir.so
    00246000 64K r-x-- /lib/tls/i686/cmov/libresolv-2.10.1.so
    00256000 4K r---- /lib/tls/i686/cmov/libresolv-2.10.1.so
    00257000 4K rw--- /lib/tls/i686/cmov/libresolv-2.10.1.so
    00258000 8K rw--- [ anon ]
    00260000 36K r-x-- /lib/tls/i686/cmov/libcrypt-2.10.1.so
    00269000 4K r---- /lib/tls/i686/cmov/libcrypt-2.10.1.so
    0026a000 4K rw--- /lib/tls/i686/cmov/libcrypt-2.10.1.so
    0026b000 156K rw--- [ anon ]
    00292000 112K r-x-- /lib/libgcc_s.so.1
    002ae000 4K r---- /lib/libgcc_s.so.1
    002af000 4K rw--- /lib/libgcc_s.so.1
    002b9000 12K r-x-- /lib/libuuid.so.1.3.0
    002bc000 4K r---- /lib/libuuid.so.1.3.0
    002bd000 4K rw--- /lib/libuuid.so.1.3.0
    002be000 260K r-x-- /lib/i686/cmov/libssl.so.0.9.8
    002ff000 4K ----- /lib/i686/cmov/libssl.so.0.9.8
    00300000 4K r---- /lib/i686/cmov/libssl.so.0.9.8
    00301000 12K rw--- /lib/i686/cmov/libssl.so.0.9.8
    00304000 152K r-x-- /usr/lib/libk5crypto.so.3.1
    0032a000 4K ----- /usr/lib/libk5crypto.so.3.1
    0032b000 4K r---- /usr/lib/libk5crypto.so.3.1
    0032c000 4K rw--- /usr/lib/libk5crypto.so.3.1
    00349000 144K r-x-- /lib/libexpat.so.1.5.2
    0036d000 8K r---- /lib/libexpat.so.1.5.2
    0036f000 4K rw--- /lib/libexpat.so.1.5.2
    00385000 4K r-x-- /usr/lib/apache2/modules/mod_authz_user.so
    00386000 4K r---- /usr/lib/apache2/modules/mod_authz_user.so
    00387000 4K rw--- /usr/lib/apache2/modules/mod_authz_user.so
    003ec000 160K r-x-- /usr/lib/libgssapi_krb5.so.2.2
    00414000 4K r---- /usr/lib/libgssapi_krb5.so.2.2
    00415000 4K rw--- /usr/lib/libgssapi_krb5.so.2.2
    00416000 636K r-x-- /usr/lib/libkrb5.so.3.3
    004b5000 4K ----- /usr/lib/libkrb5.so.3.3
    004b6000 20K r---- /usr/lib/libkrb5.so.3.3
    004bb000 4K rw--- /usr/lib/libkrb5.so.3.3
    004e3000 8K r-x-- /usr/lib/apache2/modules/mod_alias.so
    004e5000 4K ----- /usr/lib/apache2/modules/mod_alias.so
    004e6000 4K r---- /usr/lib/apache2/modules/mod_alias.so
    004e7000 4K rw--- /usr/lib/apache2/modules/mod_alias.so
    00501000 8K r-x-- /usr/lib/apache2/modules/mod_setenvif.so
    00503000 4K r---- /usr/lib/apache2/modules/mod_setenvif.so
    00504000 4K rw--- /usr/lib/apache2/modules/mod_setenvif.so
    0060f000 8K r-x-- /usr/lib/apache2/modules/mod_authz_host.so
    00611000 4K r---- /usr/lib/apache2/modules/mod_authz_host.so
    00612000 4K rw--- /usr/lib/apache2/modules/mod_authz_host.so
    006f6000 4K r-x-- /usr/lib/apache2/modules/mod_env.so
    006f7000 4K r---- /usr/lib/apache2/modules/mod_env.so
    006f8000 4K rw--- /usr/lib/apache2/modules/mod_env.so
    006f9000 1428K r-x-- /usr/lib/libdb-4.7.so
    0085e000 8K r---- /usr/lib/libdb-4.7.so
    00860000 4K rw--- /usr/lib/libdb-4.7.so
    00907000 20K r-x-- /usr/lib/apache2/modules/mod_cgi.so
    0090c000 4K r---- /usr/lib/apache2/modules/mod_cgi.so
    0090d000 4K rw--- /usr/lib/apache2/modules/mod_cgi.so
    00950000 4K r-x-- /usr/lib/apache2/modules/mod_authz_default.so
    00951000 4K r---- /usr/lib/apache2/modules/mod_authz_default.so
    00952000 4K rw--- /usr/lib/apache2/modules/mod_authz_default.so
    0099e000 4K r-x-- /usr/lib/apache2/modules/mod_authn_file.so
    0099f000 4K r---- /usr/lib/apache2/modules/mod_authn_file.so
    009a0000 4K rw--- /usr/lib/apache2/modules/mod_authn_file.so
    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/libkrb5support.so.0.1
    00adb000 4K r---- /usr/lib/libkrb5support.so.0.1
    00adc000 4K rw--- /usr/lib/libkrb5support.so.0.1
    00b28000 132K r-x-- /usr/lib/libaprutil-1.so.0.3.9
    00b49000 4K r---- /usr/lib/libaprutil-1.so.0.3.9
    00b4a000 4K rw--- /usr/lib/libaprutil-1.so.0.3.9
    00b66000 64K r-x-- /lib/libbz2.so.1.0.4
    00b76000 4K r---- /lib/libbz2.so.1.0.4
    00b77000 4K rw--- /lib/libbz2.so.1.0.4
    00b90000 16K r-x-- /usr/lib/apache2/modules/mod_status.so
    00b94000 4K r---- /usr/lib/apache2/modules/mod_status.so
    00b95000 4K rw--- /usr/lib/apache2/modules/mod_status.so
    00ba6000 164K r-x-- /usr/lib/libapr-1.so.0.3.8
    00bcf000 4K r---- /usr/lib/libapr-1.so.0.3.8
    00bd0000 4K rw--- /usr/lib/libapr-1.so.0.3.8
    00bf5000 12K r-x-- /usr/lib/apache2/modules/mod_mime.so
    00bf8000 4K r---- /usr/lib/apache2/modules/mod_mime.so
    00bf9000 4K rw--- /usr/lib/apache2/modules/mod_mime.so
    00c7e000 40K r-x-- /lib/tls/i686/cmov/libnss_files-2.10.1.so
    00c88000 4K r---- /lib/tls/i686/cmov/libnss_files-2.10.1.so
    00c89000 4K rw--- /lib/tls/i686/cmov/libnss_files-2.10.1.so
    00ce9000 1272K r-x-- /lib/tls/i686/cmov/libc-2.10.1.so
    00e27000 8K r---- /lib/tls/i686/cmov/libc-2.10.1.so
    00e29000 4K rw--- /lib/tls/i686/cmov/libc-2.10.1.so
    00e2a000 12K rw--- [ anon ]
    00e67000 84K r-x-- /lib/tls/i686/cmov/libpthread-2.10.1.so
    00e7c000 4K r---- /lib/tls/i686/cmov/libpthread-2.10.1.so
    00e7d000 4K rw--- /lib/tls/i686/cmov/libpthread-2.10.1.so
    00e7e000 8K rw--- [ anon ]
    00f69000 108K r-x-- /lib/ld-2.10.1.so
    00f84000 4K r---- /lib/ld-2.10.1.so
    00f85000 4K rw--- /lib/ld-2.10.1.so
    00f9d000 8K r-x-- /lib/tls/i686/cmov/libdl-2.10.1.so
    00f9f000 4K r---- /lib/tls/i686/cmov/libdl-2.10.1.so
    00fa0000 4K rw--- /lib/tls/i686/cmov/libdl-2.10.1.so
    00fa1000 5036K r-x-- /usr/lib/apache2/modules/libphp5.so
    0148c000 4K ----- /usr/lib/apache2/modules/libphp5.so
    0148d000 68K r---- /usr/lib/apache2/modules/libphp5.so
    0149e000 148K rw--- /usr/lib/apache2/modules/libphp5.so
    014c3000 20K rw--- [ anon ]
    01cc1000 1204K r-x-- /lib/i686/cmov/libcrypto.so.0.9.8
    01dee000 32K r---- /lib/i686/cmov/libcrypto.so.0.9.8
    01df6000 52K rw--- /lib/i686/cmov/libcrypto.so.0.9.8
    01e03000 16K rw--- [ anon ]
    03087000 1716K r-x-- /usr/lib/libmysqlclient_r.so.16.0.0
    03234000 12K r---- /usr/lib/libmysqlclient_r.so.16.0.0
    03237000 276K rw--- /usr/lib/libmysqlclient_r.so.16.0.0
    0327c000 4K rw--- [ anon ]
    06147000 1160K r-x-- /usr/lib/libxml2.so.2.7.5
    06269000 4K ----- /usr/lib/libxml2.so.2.7.5
    0626a000 16K r---- /usr/lib/libxml2.so.2.7.5
    0626e000 4K rw--- /usr/lib/libxml2.so.2.7.5
    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?

    0 comments

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

    Example
    #ps -u rajesh u

    or

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

    Example
    #lsof grep rajesh

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

    Example
    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?

    0 comments

    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 :

    PID TTY TIME CMD
    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 :

    UID PID PPID C STIME TTY TIME CMD
    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"
    #pstree

    Example output :

    init─┬─NetworkManager─┬─pppd
    │ └─{NetworkManager}
    ├─acpid
    ├─apache2───6*[apache2]
    ├─atd
    ├─avahi-daemon───avahi-daemon
    ├─bonobo-activati───{bonobo-activati}
    ├─console-kit-dae───63*[{console-kit-dae}]
    ├─cron
    ├─2*[dbus-daemon]
    ├─2*[dbus-launch]

    To see all the files opened
    #lsof

    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/libdbus-glib-1.so.2.1.0
    hald-addo 2384 root mem REG 8,8 30684 2537 /lib/tls/i686/cmov/librt-2.10.1.so
    hald-addo 2384 root mem REG 8,8 743912 1332 /lib/libglib-2.0.so.0.2200.2
    hald-addo 2384 root mem REG 8,8 1319364 2507 /lib/tls/i686/cmov/libc-2.10.1.so
    hald-addo 2384 root mem REG 8,8 247788 5986 /usr/lib/libgobject-2.0.so.0.2200.2
    hald-addo 2384 root mem REG 8,8 116920 2533 /lib/tls/i686/cmov/libpthread-2.10.1.so
    hald-addo 2384 root mem REG 8,8 113320 1278 /lib/ld-2.10.1.so
    hald-addo 2384 root mem REG 8,8 227000 1314 /lib/libdbus-1.so.3.4.0
    hald-addo 2384 root mem REG 8,8 193860 1383 /lib/libpcre.so.3.12.1
    hald-addo 2384 root mem REG 8,8 71144 6123 /usr/lib/libhal.so.1.0.0


    To see the process in dynamic way
    #top

    #atop

    #htop

    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