linux - 如何找出 Linux 中哪些进程正在使用交换空间?

标签 linux memory swap

在 Linux 下,如何找出哪个进程使用交换空间更多?

最佳答案

我找到的最好的脚本在这个页面上:http://northernmost.org/blog/find-out-what-is-using-your-swap/

这是脚本的一种变体,不需要 root:

#!/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"

关于linux - 如何找出 Linux 中哪些进程正在使用交换空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10580767/

相关文章:

node.js - Linux 上的 NodeJS USB 模块问题

c++ - 另一个类内部类的内存释放

c - 动态数组在通过引用传递时交换列和行

c++ - 通过 dlsym 访问 C 中的阴影全局变量不起作用

linux - Shell 脚本帮助复制他们删除的目录

c++ - 串口通讯

ios - UIViewController 已正确释放,但其 UIView 未正确释放?

c - brk() 、 sbrk() 和 realloc() 函数之间的区别

c++ - 使用引用或指针通过 xor 运算符交换两个变量的值

c++ - 切换 QDeclarativeView 的源