Thứ Năm, 27 tháng 7, 2017

Linux: Find Out What Process Are Using Swap Space

The top and free command display the total amount of free and used physical and swap memory in the server. How do I determine which process is using swap space under Linux operating systems? How do I find out swap space usage of particular process such as memcached?

You can use the any one of the following techniques but keep in mind that because of shared pages, there is no reliable way to get this information[1]

[a] /proc/meminfo – This file reports statistics about memory usage on the system. It is used by free to report the amount of free and used memory (both physical and swap) on the system as well as the shared memory and buffers used by the kernel. You can also use free, vmstat and other tools to find out the same information.


[b] /proc/${PID}/smaps, /proc/${PID}/status, and /proc/${PID}/stat : Use these files to find information about memory, pages and swap used by each process using its PID.

[c] smem – This command (python script) reports memory usage with shared memory divided proportionally.

Finding out process ID and swap usage

Type the following pidof command to find the process ID of a running program called memcached:
# pidof memcached

Alternatively, use pgrep command to lookup process PID, enter:
# pgrep memcached

Sample outputs (note down PID number #1):

48440
To see swap space used by memcached (PID # 48440), enter (number #2):
# grep --color VmSwap /proc/48440/status

Sample outputs (number #4):

VmSwap:         900 kB
Or the following awk command (number #3):
# awk '/VmSwap/{print $2 " " $3}' /proc/48440/status

Sample outputs (number #4):

Fig.01: Finding out memcached process swap usage
Fig.01: Finding out memcached process swap usage
Listing all process swap space usage

Type the following bash for loop command to see swap space usage per process:

for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done
Type the following command to sort out output:

for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less
Sample outputs:

php-cgi 11964 kB
php-cgi 11016 kB
php-cgi 10392 kB
php-cgi 10336 kB
php-cgi 9844 kB
php-cgi 9780 kB
php-cgi 8584 kB
php-cgi 7996 kB
php-cgi 7960 kB
php-cgi 7956 kB
php-cgi 7796 kB
php-cgi 7540 kB
php-cgi 6884 kB
squid 6864 kB
php-cgi 6640 kB
php-cgi 6556 kB
php-cgi 5848 kB
php-cgi 5744 kB
php-cgi 5636 kB
php-cgi 5592 kB
php-cgi 5488 kB
php-cgi 5132 kB
php-cgi 4584 kB
php-cgi 4508 kB
php-cgi 4388 kB
lighttpd 4100 kB
php-cgi 3984 kB
php-cgi 3644 kB
php-cgi 3616 kB
php-cgi 3604 kB
rpc.mountd 3580 kB

Share This!


1 nhận xét:

  1. 10 Tut - Sharing Tip And Tut: Linux: Find Out What Process Are Using Swap Space >>>>> Download Now

    >>>>> Download Full

    10 Tut - Sharing Tip And Tut: Linux: Find Out What Process Are Using Swap Space >>>>> Download LINK

    >>>>> Download Now

    10 Tut - Sharing Tip And Tut: Linux: Find Out What Process Are Using Swap Space >>>>> Download Full

    >>>>> Download LINK

    Trả lờiXóa