1
我用下面的脚本(从这个博客http://northernmost.org/blog/find-out-what-is-using-your-swap)知道每个进程是多少互换使用知道多少交换所使用的每一个过程在Linux上
#!/bin/bash
# Get current swap usage for all running processes
# Erik Ljungstrom 27/05/2011
SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do
PID=`echo $DIR | cut -d/-f 3`
PROGNAME=`ps -p $PID -o comm --no-headers`
for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`
do
let SUM=$SUM+$SWAP
done
echo "PID=$PID - Swap used: $SUM - ($PROGNAME)"
let OVERALL=$OVERALL+$SUM
SUM=0
done
echo "Overall swap used: $OVERALL"
此使用的输出总交换脚本与免费命令输出使用的输出不匹配。
有人能解释为什么吗?
内核可以使用一些交换空间来管理。我怀疑这是你所看到的。 IIRC,'mmap''d文件在某些情况下使用交换。 – JimR 2013-10-09 20:36:39
可能重复[如何找出哪些进程交换在Linux?](http://stackoverflow.com/questions/479953/how-to-find-out-which-processes-are-swapping-in-linux) – harrymc 2013-11-28 18:36:47