Skip to content

Instantly share code, notes, and snippets.

@rubenruizdegauna
Created October 31, 2014 10:14
Show Gist options
  • Save rubenruizdegauna/bf8161a5b664ca85636d to your computer and use it in GitHub Desktop.
Save rubenruizdegauna/bf8161a5b664ca85636d to your computer and use it in GitHub Desktop.
Prints all the processes (swap amount, pid and name w/o params) that are using swap ordered by swap amount
#!/usr/bin/env bash
# Prints all the processes that are using swap ordered by swap amount (DESC)
for PID in $( ls /proc/|egrep "^[0-9]" );do
PROCNAME=$( ps -e -o pid,comm|grep ${PID}|awk '{print $2}' )
awk -v PID=${PID} -v PROCNAME=${PROCNAME} '/Swap/{sum+=$2}END{print (sum/1024)"\t"PID"\t"PROCNAME}' /proc/${PID}/smaps 2>/dev/null |egrep -v "^0"
done | sort -nr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment