linux什么时候使用swap,linux – 我怎么知道哪个进程使用swap?

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.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值