#! /Bin/bashecho-e 'date + % y % m % d % H % M' echo-e & quot; PID \ t \ tSwap \ t \ tProc_Name & quot; # show all the directories named after numbers in the/proc directory (the process name is a number, and others such as sys and net store other information) forpidin 'ls-l/proc | grep ^ d | awk & #39 ;{
#! /Bin/bash echo-e 'date + % y % m % d % H % M' echo-e "PID \ t \ tSwap \ t \ tProc_Name" # output/proc directory all the directories named after numbers (the process name is a number, other information such as sys and net is stored) for pid in 'ls-l/proc | grep ^ d | awk '{print $9}' | grep-v [^ 0-9] 'Do # let the process release swap there is only one method: restart the process. Or wait until it is released automatically. Release # if the process is automatically released, we will not write the script to find him, because he is not automatically released. # So we need to list the processes that occupy swap and need to be restarted, but the init process is the ancestor process of all processes in the system # restarting the init process means restarting the system, which is totally unavailable, so you don't have to detect him to avoid system impact. If [$ pid-eq 1]; then continue; fi grep-q "Swap"/proc/$ pid/smaps 2>/dev/null if [$? -Eq 0]; then swap =$ (grep Swap/proc/$ pid/smaps \ | gawk '{sum + = $2;} END {print sum }') proc_name = $ (ps aux | grep-w "$ pid" | grep-v grep \ | awk '{for (I = 11; I <= NF; I ++) {printf ("% s", $ I) ;}') if [$ swap-gt 0]; then echo-e "$ {pid} \ t $ {swap} \ t $ {proc_name}" fi fidone | sort-k2-n | awk-f' \ t ''{ pid [NR] = $1; size [NR] = $2; name [NR] = $3;} END {for (id = 1; id <= length (pid); id ++) {if (size [id] <1024) printf ("%-10s \ t % 15sKB \ t % s \ n", pid [id], size [id], name [id]); else if (size [id] <1048576) printf ("%-10s \ t % 15.2fMB \ t % s \ n", pid [id], size [id]/1024, name [id]); else printf ("%-10s \ t % 15.2fGB \ t % s \ n", pid [id], size [id]/1048576, name [id]) ;}}'
We recommend that you perform scheduled tasks to monitor swap space usage. sh>/root/swap. after monitoring, some java processes occupy the swap space and are not released. after killing these java processes, swap is released.
Ps: http://blog.itpub.net/26972107/viewspace-774239