且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-01-17 22:38:30

Run top 然后按 OpEnter.现在进程应该按照它们的交换使用情况进行排序.

Run top then press OpEnter. Now processes should be sorted by their swap usage.

这是一个更新,因为我的原始答案没有提供评论中指出的问题的确切答案.来自 htop 常见问题:

Here is an update as my original answer does not provide an exact answer to the problem as pointed out in the comments. From the htop FAQ:

无法获得已用交换空间的确切大小过程.Top 通过使 SWAP = VIRT - RES 伪造此信息,但是这不是一个好的指标,因为其他东西,如视频内存也依赖于 VIRT(例如:top 说我的 X 进程正在使用81M 的交换,但它也报告我的系统作为一个整体只使用了 2M的交换.因此,我不会在 htop 中添加类似的 Swap 列因为我不知道获取这些信息的可靠方法(实际上,我认为不可能得到一个确切的数字,因为共享页).

It is not possible to get the exact size of used swap space of a process. Top fakes this information by making SWAP = VIRT - RES, but that is not a good metric, because other stuff such as video memory counts on VIRT as well (for example: top says my X process is using 81M of swap, but it also reports my system as a whole is using only 2M of swap. Therefore, I will not add a similar Swap column to htop because I don't know a reliable way to get this information (actually, I don't think it's possible to get an exact number, because of shared pages).