在 Linux 下,如何找出哪个进程使用的交换空间更多?
原文由 Shameem 发布,翻译遵循 CC BY-SA 4.0 许可协议
我找到的最好的脚本在这个页面上:http: //northernmost.org/blog/find-out-what-is-using-your-swap/
这是脚本的一种变体,不需要根:
#!/bin/bash
# Get current swap usage for all running processes
# Erik Ljungstrom 27/05/2011
# Modified by Mikko Rantalainen 2012-08-09
# Pipe the output to "sort -nk3" to get sorted output
# Modified by Marc Methot 2014-09-18
# removed the need for sudo
SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d -regex "^/proc/[0-9]+"`
do
PID=`echo $DIR | cut -d / -f 3`
PROGNAME=`ps -p $PID -o comm --no-headers`
for SWAP in `grep VmSwap $DIR/status 2>/dev/null | awk '{ print $2 }'`
do
let SUM=$SUM+$SWAP
done
if (( $SUM > 0 )); then
echo "PID=$PID swapped $SUM KB ($PROGNAME)"
fi
let OVERALL=$OVERALL+$SUM
SUM=0
done
echo "Overall swap used: $OVERALL KB"
原文由 lolotux 发布,翻译遵循 CC BY-SA 3.0 许可协议
7 回答5.3k 阅读
4 回答4k 阅读
2 回答5.9k 阅读✓ 已解决
2 回答2.5k 阅读✓ 已解决
1 回答2.3k 阅读✓ 已解决
2 回答799 阅读✓ 已解决
2 回答3.2k 阅读
运行 top 然后按
O
p
Enter
。现在应该按照它们的交换使用对进程进行排序。这是一个更新,因为我的原始答案没有提供评论中指出的问题的确切答案。从 htop 常见问题解答: