P
P
Puma Thailand2012-11-10 07:38:08
linux
Puma Thailand, 2012-11-10 07:38:08

How to find out which process got into swap in linux

Someone eats swap and does not want to get out of it when free memory appears, everything is solved by swapoff -a, but I would like to know which process was currently moved to swap.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
L
lirvux, 2012-11-10
@opium

in top:
press f - the column setting for output appears
; press p - turn on the swap column.
in htop:
press f2, go to columns, right twice, select nswap and press f5

F
Fedor, 2012-11-10
@FFF

Using the nswap column in the TOP to detect processes that have already gone into swap is not entirely correct. You can read more here . They also provide a simple bash script with which you can easily get a list of all the processes that eat your swap.

D
Denis, 2012-11-10
@uscr

This is normal behavior. Linux knows better than you what should be in memory and what can be left in the swap. Believe him.

V
Vladimir Zhurkin, 2019-11-14
@icCE

Found a great script!

#!/bin/bash
# Get current swap usage for all running processes
# Erik Ljungstrom 05/27/2011
# Modified by Mikko Rantalainen 2012-08-09
# Pipe the output to "sort -nk3" to get sorted output
# Modified by Marc Methot 2014-09-18
# removed the need for sudo
SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d -regex "^/proc/[0-9]+"`
do
PID =`echo $DIR | cut -d / -f 3`
PROGNAME=`ps -p $PID -o comm --no-headers`
for SWAP in `grep VmSwap $DIR/status 2>/dev/null | awk '{ print $2 }'`
do
let SUM=$SUM+$SWAP
done
if (( $SUM > 0 )); then
echo "PID=$PID swapped $SUM KB ($PROGNAME)"
fi
let OVERALL=$OVERALL+$SUM
SUM=0
done
echo "Overall swap used: $OVERALL KB"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question