加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 我怎么知道哪个进程使用swap?

发布时间:2020-12-14 02:54:39 所属栏目:Linux 来源:网络整理
导读:有很多可用的内存(大约4G)但在我的软呢帽中使用了交换(200 M). 我想知道哪个进程使用swap.我怎么知道呢. ps和top仅显示内存使用情况. 提前致谢. 解决方法 从 here开始: [a] /proc/meminfo – This file reports statistics about memory usage on the syste
有很多可用的内存(大约4G)但在我的软呢帽中使用了交换(200 M).

我想知道哪个进程使用swap.我怎么知道呢.

ps和top仅显示内存使用情况.

提前致谢.

解决方法

从 here开始:

[a] /proc/meminfo – This file reports statistics about memory usage on
the system. It is used by free to report the amount of free and used
memory (both physical and swap) on the system as well as the shared
memory and buffers used by the kernel. You can also use free,vmstat
and other tools to find out the same information.

[b]
/proc/${PID}/smaps,/proc/${PID}/status,and /proc/${PID}/stat : Use
these files to find information about memory,pages and swap used by
each process using its PID.

[c] smem – This command (python script) reports memory usage with
shared memory divided proportionally.

你也可以参考Find out what is using your swap

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读