Код: Выделить всё
#!/bin/bash
# Get current swap usage for all running processes
# Erik Ljungstrom 27/05/2011
# Modified by Mikko Rantalainen 2012-08-09
# Pipe the output to "sort -nk3" to get sorted output
SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d -regex "^/proc/[0-9]+"`
do
PID=`echo $DIR | cut -d / -f 3`
PROGNAME=`ps -p $PID -o comm --no-headers`
for SWAP in `grep Swap $DIR/smaps 2>/dev/null | awk '{ print $2 }'`
do
let SUM=$SUM+$SWAP
done
if (( $SUM > 0 )); then
echo "PID=$PID swapped $SUM KB ($PROGNAME)"
fi
let OVERALL=$OVERALL+$SUM
SUM=0
done
echo "Overall swap used: $OVERALL KB"
Код: Выделить всё
# ./swapusage
PID=1 swapped 92 KB (init)
PID=573 swapped 312 KB (udevd)
PID=2422 swapped 124 KB (auditd)
PID=2496 swapped 324 KB (rsyslogd)
PID=2508 swapped 92 KB (irqbalance)
PID=2561 swapped 124 KB (dbus-daemon)
PID=2590 swapped 104 KB (acpid)
PID=2599 swapped 308 KB (hald)
PID=2600 swapped 180 KB (hald-runner)
PID=2628 swapped 152 KB (hald-addon-inpu)
PID=2634 swapped 268 KB (crond)
PID=2637 swapped 140 KB (hald-addon-acpi)
PID=2655 swapped 572 KB (sshd)
PID=2663 swapped 316 KB (ntpd)
PID=3331 swapped 56 KB (abrtd)
PID=3339 swapped 92 KB (abrt-dump-oops)
PID=3386 swapped 552 KB (pure-ftpd)
PID=3388 swapped 400 KB (pure-authd)
PID=3407 swapped 124 KB (atd)
PID=3432 swapped 36 KB (sys-snap.sh)
PID=3707 swapped 1336 KB (cphulkd)
PID=3730 swapped 13284 KB (cpdavd)
PID=3749 swapped 1780 KB (queueprocd)
PID=3788 swapped 900 KB (cpanellogd)
PID=4284 swapped 4248 KB (python)
PID=4321 swapped 68 KB (mingetty)
PID=4323 swapped 68 KB (mingetty)
PID=4325 swapped 64 KB (mingetty)
PID=4327 swapped 64 KB (mingetty)
PID=4329 swapped 68 KB (mingetty)
PID=4331 swapped 68 KB (mingetty)
PID=4336 swapped 272 KB (udevd)
PID=17411 swapped 156 KB (crond)
PID=24577 swapped 20 KB (screen)
PID=28021 swapped 268 KB (udevd)
Overall swap used: 27032 KB