Under Linux, how do I find out which process is using the swap space more?
Join Stack Overflow to learn, share knowledge, and build your career.
|
|
Run top then press OpEnter. Now processes should be sorted by their swap usage. 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:
|
|||||||||||||||||||||
|
|
The best script I found is on this page : http://northernmost.org/blog/find-out-what-is-using-your-swap/ Here's one variant of the script and no root needed:
|
|||||||||||||||||||||
|
|
Here's another variant of the script, but meant to give more readable output (you need to run this as root to get exact results):
|
|||||||||||||||||
|
|
It's not entirely clear if you mean you want to find the process who has most pages swapped out or process who caused most pages to be swapped out. For the first you may run |
|||
|
|
|
I did notice this thread is rather old, but if you happen to stumble upon it, as I just did, another answer is: use smem. Here is a link which tells you both how to install it and how to use it: http://www.cyberciti.biz/faq/linux-which-process-is-using-swap/ |
|||||||||
|
|
The top command also contains a field to display the number of page faults for a process. The process with maximum page faults would be the process which is swapping most. For long running daemons it might be that they incur large number of page faults at the beginning and the number does not increase later on. So we need to observe whether the page faults is increasing. |
|||
|
|
|
Another script variant avoiding the loop in shell:
Standard usage is I hope I've commented the code enough to tell what it does. |
|||||||||||||||||||||
|
Yet a shell variant! (Not bash only)This is exactly same than lolotux script, but without any fork to And as bash is one of the poorest shell regarding performance, a little work was done to ensure this script will run well under dash, busybox and some other. Then, (thanks to Stéphane Chazelas,) become a lot quicker again!
Don't forgot to double quote
Don't try Perl versionAs this become a not so simple script, time is comming to write a dedicated tool by using more efficient language.
could by run with one of
|
|||||||||||||||||||||
|
|
I suppose you could get a good guess by running Swapping is a function of having more memory in active use than is installed, so it is usually hard to blame it on a single process. If it is an ongoing problem, the best solution is to install more memory, or make other systemic changes. |
||||
|
|
|
I don't know of any direct answer as how to find exactly what process is using the swap space, however, this link may be helpful. Another good one is over here Also, use a good tool like htop to see which processes are using a lot of memory and how much swap overall is being used. |
|||
|
|
|
On MacOSX, you run top command as well but need to type "o" then "vsize" then ENTER. |
|||
|
|
|
|
|||
|
|
|
I adapted a different script on the web to this long one-liner:
Which I then throw into a cronjob and redirect output to a logfile. The information here is the same as accumulating the
The output of this version is in two columns: pid, swap amount. In the above version, the |
|||||
|
protected by Yu Hao Sep 23 '13 at 8:20
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?