List all processes and how much swap they use.
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 | |
# | |
# Riyad Preukschas <riyad@informatik.uni-bremen.de> | |
# License: Mozilla Public License 2.0 | |
# SPDX-License-Identifier: MPL-2.0 | |
# | |
# List all processes and how much swap they use. | |
# The output format is: "<swap used> : <pid> : <process name>" | |
# | |
# To get the top 10 processes using swap you can run: | |
# lsswap | sort -hr | head -n10 | |
files=(/proc/*/status) | |
exec awk ' | |
BEGINFILE { | |
# skip files that cannot be opened | |
if ( ERRNO != "" ) { | |
nextfile | |
} | |
} | |
/^Name:/ { name = $2 } | |
/^Pid:/ { pid = $2 } | |
/^VmSwap:/ { vmswap = $2$3 } | |
ENDFILE { | |
# skip processes that cannot be swapped and processes not using swap at all | |
if (length(vmswap) > 0 && vmswap != "0kB") { | |
print vmswap " : " pid " : " name | |
} | |
} | |
' "${files[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment