How to find out which processes are using swap space in Linux?

后端 未结 18 2005
终归单人心
终归单人心 2020-11-27 09:11

Under Linux, how do I find out which process is using the swap space more?

18条回答
  •  甜味超标
    2020-11-27 09:28

    You can use Procpath (author here), to simplify parsing of VmSwap from /proc/$PID/status.

    $ procpath record -f stat,cmdline,status -r 1 -d db.sqlite
    $ sqlite3 -column db.sqlite \
      'SELECT status_name, status_vmswap FROM record ORDER BY status_vmswap DESC LIMIT 5'
    Web Content  192136       
    okular       186872       
    thunderbird  183692       
    Web Content  143404       
    MainThread   86300
    

    You can also plot VmSwap of processes of interest over time like this. Here I'm recording my Firefox process tree while opening a couple tens of tabs along with statrting a memory-hungry application to try to cause it to swap (which wasn't convincing for Firefox, but your kilometrage may vary).

    $ procpath record -f stat,cmdline,status -i 1 -d db2.sqlite \
      '$..children[?(@.stat.pid == 6029)]'
    # interrupt by Ctrl+C
    $ procpath plot -d db2.sqlite -q cpu --custom-value-expr status_vmswap \
      --title "CPU usage, % vs Swap, kB"
    

提交回复
热议问题