Skip to content

Instantly share code, notes, and snippets.

@aravindkumarsvg
Created March 29, 2018 10:39
Show Gist options
  • Save aravindkumarsvg/09c6e86a6a909de543946c459a70e04a to your computer and use it in GitHub Desktop.
Save aravindkumarsvg/09c6e86a6a909de543946c459a70e04a to your computer and use it in GitHub Desktop.
Gets the processes which is using the swap space
#!/bin/bash
# Loops through the proc directory
for processId in `ls /proc/`; do
# Checks for the status file for a process
if [[ $processId =~ ^[0-9]+$ && -r "/proc/${processId}/status" ]]; then
# Gets the swap space usage for the process
swapUsage=`grep VmSwap "/proc/${processId}/status" | awk '{print $2}'`
if [[ ! -z $swapUsage && $swapUsage > 0 ]]; then
# Gets the process name
processName=`ps -p $processId -o comm=`
echo "${swapUsage} ---- ${processId} ---- ${processName}"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment