#!/bin/bash
#Filename:check_swap.sh
echo -e "PIDttSwapttProc_Name"
# 取/proc目录下所有以数字为名的目录(进程名是数字才是进程)
(for pid in `ls -l /proc | grep ^d | linuxjishu/13830.html target=_blank class=infotextkey>awk '{ print $8 }'| grep -v ^[^0-9]`
do
if [ ! -e /proc/$pid ];then
continue
fi
PName=$(cat /proc/$pid/cmdline)
awk -v name=$PName -v pid=$pid '
{
if($1 ~ /^Swap/)
{
swap += $2
}
}
END{
if(swap != 0)
print pid"tt"swap" kbtt"name
}' /proc/$pid/smaps 2>/dev/null
done) | sort -rnk2
PID Swap Proc_Name
356 816 kb udevd--daemon
355 788 kb udevd--daemon
265 776 kb udevd--daemon
507 664 kb rsyslogd-c4
827 484 kb /usr/sbin/cupsd-F
617 480 kb NetworkManager
434 428 kb /usr/sbin/sshd-D
829 424 kb gdm-binary
671 420 kb /usr/lib/policykit-1/polkitd
667 304 kb /usr/sbin/modem-manager
700 272 kb /sbin/wpa_supplicant-u-s
732 172 kb acpid-c/etc/acpi/events-s/var/run/acpid.socket
705 168 kb /sbin/dhclient-d-4-sf/usr/lib/NetworkManager/nm-dhcp-client.action-pf/var/run/dhclient-
eth0.pid-lf/var/lib/dhcp/dhclient-352800b5-14dd-4450-b596-a407f9cebf0f-eth0.lease-cf/var/run/nm-dhclient-eth0.confeth0
252 164 kb upstart-udev-bridge--daemon
526 136 kb dbus-daemon--system--fork--activation=upstart
1 120 kb /sbin/init
735 112 kb atd
734 112 kb cron
726 80 kb /sbin/getty-838400tty2
715 80 kb /sbin/getty-838400tty4
730 76 kb /sbin/getty-838400tty6
727 76 kb /sbin/getty-838400tty3
719 76 kb /sbin/getty-838400tty5
837 64 kb /usr/sbin/console-kit-daemon--no-daemon
599 64 kb upstart-socket-bridge--daemon
1202 4 kb /usr/bin/gnome-keyring-daemon--daemonize--login
1062 4 kb /sbin/getty-838400tty1