Skip to content

Instantly share code, notes, and snippets.

@kode54
Created October 6, 2022 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kode54/f66aeadcddca471ed7a469e98e568f1c to your computer and use it in GitHub Desktop.
Save kode54/f66aeadcddca471ed7a469e98e568f1c to your computer and use it in GitHub Desktop.
Swap Info script for bash, not originally mine
#!/bin/bash
overall=0
outlist=""
for status_file in /proc/[0-9]*/status; do
swap_mem=$(grep VmSwap "$status_file" | awk '{ print $2 }')
if [ "$swap_mem" ] && [ "$swap_mem" -gt 0 ]; then
pid=$(grep Tgid "$status_file" | awk '{ print $2 }')
name=$(grep Name "$status_file" | awk '{ print $2 }')
printf -v output "%s\t%s\t%s KB\n" "$pid" "$name" "$swap_mem"
outlist="$outlist$output"
fi
overall=$((overall+swap_mem))
done
printf "%s" "$outlist" | sort -k 3 -n -r
printf "Total Swapped Memory: %14u KB\n" $overall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment