Under Linux, how do I find out which process is using the swap space more?
相关问题
- What uses more memory in c++? An 2 ints or 2 funct
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Memory for python.exe on Windows 7 python 32 - Num
- Error building gcc 4.8.3 from source: libstdc++.so
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):
Yet two more variants:
A shell variant! (Not bash only)
This is exactly same than lolotux script, but without any fork to
grep
,awk
orps
. This is a lot quicker!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
"$PROGNAME"
! See Stéphane Chazelas's comment:Don't try
echo $PROGNAME
without double quote on sensible system, and be ready to kill current shell before!And a perl version
As 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
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.
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:
iotop
is a very useful tool. It gives live stats of I/O and swap usage per process/thread. By default it shows per thread but you can doiotop -P
to get per process info. This is not available by default. You may have to install via rpm/apt.I suppose you could get a good guess by running
top
and looking for active processes using a lot of memory. Doing this programatically is harder---just look at the endless debates about the Linux OOM killer heuristics.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.