Created
March 29, 2018 10:39
-
-
Save aravindkumarsvg/09c6e86a6a909de543946c459a70e04a to your computer and use it in GitHub Desktop.
Gets the processes which is using the swap space
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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