Skip to content

Instantly share code, notes, and snippets.

@thwarted
Created October 14, 2011 22:37
Show Gist options
  • Select an option

  • Save thwarted/1288564 to your computer and use it in GitHub Desktop.

Select an option

Save thwarted/1288564 to your computer and use it in GitHub Desktop.
really rough process list that includes swap and memory usage
#!/bin/bash
# print a ps listing that includes the used swap space
# inspired by Erik Ljungstrom 27/05/2011
maxwidth=$( stty -a | tr ';' '\n' | grep columns | awk '{ print $2 }' )
maxwidth=$(( maxwidth - 10 ))
pscols=vsz:10,rss:10,pid,user,pri,stime,time:12,cmd
paste <( echo SWAP ) <( ps -p $$ -o $pscols | head -1 )
for procdir in /proc/[0-9]* ; do
PID=$( basename $procdir )
x=$( ps -p $PID -o ppid,vsz --no-headers )
[ "$( echo $x )" == "2 0" ] && continue
swapused=$( cat $procdir/smaps 2>/dev/null | grep Swap: | awk 'BEGIN { sum=0 } { sum = sum + $2 } END { print sum }' )
paste <( echo $swapused ) <( ps -p $PID -o $pscols --no-headers ) | cut -c1-$maxwidth
done
echo
free | grep -E 'total|Swap'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment