Comments on: 8 Useful Commands to Monitor Swap Space Usage in Linux https://www.tecmint.com/commands-to-monitor-swap-space-usage-in-linux/ Tecmint - Linux Howtos, Tutorials, Guides, News, Tips and Tricks. Fri, 14 Jul 2023 02:45:48 +0000 hourly 1 By: Stanislav Genov https://www.tecmint.com/commands-to-monitor-swap-space-usage-in-linux/comment-page-1/#comment-1992561 Wed, 05 Apr 2023 09:28:39 +0000 http://www.tecmint.com/?p=16051#comment-1992561 In reply to Ravi Saive.

I have no experience with Mint but in Redhat Linux with ordinary users is working as well.

stani@server:~$ sudo ./swap.sh
top swap using processes that are still running:
15816 kb                /usr/bin/perl -w /opt/lpar2rrd/lpar2rrd/bin/lpar2rrd-daemon.pl
10248 kb                [splunkd pid=3066545] splunkd -p 8089 restart [process-runner]
5864 kb         splunkd -p 8089 restart
5424 kb         /usr/lib/polkit-1/polkitd --no-debug
4912 kb         /usr/sbin/rngd -f --fill-watermark=0 -x pkcs11 -x nist -D daemon:daemon
4152 kb         /usr/libexec/platform-python -Es /usr/sbin/tuned -l -P
3064 kb         /usr/lib/systemd/systemd-journald
2027 kb         (sd-pam)
1464 kb         /usr/sbin/sshd -D
920 kb          /usr/libexec/postfix/master -w
]]>
By: Ravi Saive https://www.tecmint.com/commands-to-monitor-swap-space-usage-in-linux/comment-page-1/#comment-1992558 Wed, 05 Apr 2023 09:09:07 +0000 http://www.tecmint.com/?p=16051#comment-1992558 In reply to Stanislav Genov.

@Stanislav,

Thanks, yes it seems permission issue, as I am running the script as a sudo user. Could you make the script workable with sudo privileges?

]]>
By: Stanislav Genov https://www.tecmint.com/commands-to-monitor-swap-space-usage-in-linux/comment-page-1/#comment-1992514 Wed, 05 Apr 2023 07:13:32 +0000 http://www.tecmint.com/?p=16051#comment-1992514 In reply to Ravi Saive.

Hi Ravi, seems you have no rights in /tmp, check the permissions:

Here is the output from RedHat 8.7

root@vxltsap001:~# ./swap.sh
top swap using processes which are still running:
251000 kb               /usr/libexec/packagekitd
126384 kb               /opt/commvault/commvault/Base/cvd
68564 kb                splunkd -p 8089 restart
48632 kb                /usr/sbin/rsyslogd -n
43776 kb                /app/code-server/lib/node /app/code-server --bind-addr 0.0.0.0:8443 --user-data-dir /config/data --extensions-dir 
                        /config/extensions --disable-telemetry --auth none  /config/workspace
30584 kb                /opt/commvault/commvault/Base/ClMgrS
24860 kb                [splunkd pid=1278354] splunkd -p 8089 restart [process-runner]
17424 kb                /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8443 -container-ip 172.18.0.2 -container-port 8443
17376 kb                /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 80 -container-ip 172.18.0.3 -container-port 80
17352 kb                /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 80 -container-ip 172.18.0.3 -container-port 80
]]>
By: Ravi Saive https://www.tecmint.com/commands-to-monitor-swap-space-usage-in-linux/comment-page-1/#comment-1992460 Wed, 05 Apr 2023 04:22:41 +0000 http://www.tecmint.com/?p=16051#comment-1992460 In reply to Stanislav Genov.

@Stanislav,

I tried running the script on my Linux Mint, but getting the following error.

./swa.sh: 1: cannot create /tmp/ps_ax.output: Permission denied
./swa.sh: 2: cannot create /tmp/results: Permission denied
top swap using processes that are still running:
]]>
By: Stanislav Genov https://www.tecmint.com/commands-to-monitor-swap-space-usage-in-linux/comment-page-1/#comment-1992226 Tue, 04 Apr 2023 14:47:36 +0000 http://www.tecmint.com/?p=16051#comment-1992226 I prefer to create a simple bash script with the content below:

ps ax -o pid,args | grep -v '^  PID'|sed -e 's,^ *,,' > /tmp/ps_ax.output
echo -n >/tmp/results

for swappid in $(grep -l Swap /proc/[1-9]*/smaps ); do
        swapusage=0
        for x in $( grep Swap $swappid 2>/dev/null |grep -v '\W0 kB'|awk '{print $2}' ); do
                let swapusage+=$x
        done
        pid=$(echo $swappid| cut -d' ' -f3|cut -d'/' -f3)
        if ( [ $swapusage -ne 0 ] ); then
                echo -ne "$swapusage kb\t\t" >>/tmp/results
                egrep "^$pid " /tmp/ps_ax.output |sed -e 's,^[0-9]* ,,' >>/tmp/results
        fi
done

echo "top swap using processes which are still running:"
sort -nr /tmp/results | head -n 10

Result will be the top 10 processes using swap.

]]>