How To Check Swap Usage of Each Processes (文档 ID 1931980.1)

本文档介绍如何查看每个进程的交换内存使用情况,提供适用于所有内核版本的方法,以及针对UEK2(2.6.39)或更高版本内核的简化方法。通过解析/proc/<PID>/smaps或/proc/<PID>/status文件,可以获取进程的交换内存大小,进而找出消耗最大交换空间的进程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How To Check Swap Usage of Each Processes (文档 ID 1931980.1)

GOAL

This document shows how to check swap usage of each processes, answering "How can I know what process would consume the largest swap space?"
 

SOLUTION

For all kernels:

Swap usage is shown as "Swap" columns in /proc/<PID>/smaps. This indicates swapped memory size of the each memory ranges, thus the sum of all of these values shows the total swap usage of the process.

For example, the simple script below calculates the total swap usage of the process which PID = 1027:

# echo $((`grep Swap /proc/1027/smaps | awk '{ print $2; }' | tr '\n' '+'`0))

 

For UEK2(2.6.39) or later kernels:

It is easier to check the swap usage of a specific process, just check "VmSwap" column in /proc/<PID>/status. This indicates the total usage of the swap space as one value. This column does not exist in /proc/<PID>/status with kernel < 2.6.39.

For example, for sorting processes with the swap usage from larger, run a script below:

# for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | more

 

 The value which is shown/calculated in this document does not indicate accurate size of used swap space, but  just indicates rough approximate one. Some(like shared library) could be double counted, and others(like swap cache) are not really swapped.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值