GOAL
Find proccesses which uses swap
SOLUTION
Summary by processes
#!/bin/bash echo -n "" > /tmp/swapusage.output for i in $( ps -e -o pid --no-headers); do swapusage=$(grep Swap "/proc/$i/smaps"| grep -v '\W0 kB' | awk '{s+=$2} END {print s}') if [ ! -z "$swapusage" ]; then cmd=$(ps -p $i -o user,cmd --no-headers | cut -d" " -f 1) printf "%s\t%-40s\t\t\t%s\n" $i $cmd $swapusage >> /tmp/swapusage.output fi ; done echo -e "PID\tCMD\t\t\t\t\t\t\t\tSWAP kB" echo "--------------------------------------------------------------------------------" sort -k 3 -n /tmp/swapusage.output
# ps ax | sed "s/^ *//" > /tmp/ps_ax.output # for x in $(grep Swap /proc/[1-9]*/smaps | grep -v '\W0 kB' | tr -s ' ' | cut -d' ' -f-2 | sort -t' ' -k2 -n | tr -d ' ' | tail -20); do swapusage=$(echo $x | cut -d: -f3) pid=$(echo $x | cut -d/ -f3) procname=$(cat /tmp/ps_ax.output | grep "^$pid ") echo "============================" echo "Process : $procname" echo "Swap usage: $swapusage kB"; done
No comments:
Post a Comment