• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How To Check Swap Usage of Each Processes in Linux

by admin

This post shows how to check swap usage of each process, answering “How can I know what process would consume the largest swap space?”

For all kernels

Swap usage is shown as “Swap” columns in /proc/[PID]/smaps. This indicates swapped memory size of the each memory ranges, thus the sum of all of these values shows the total swap usage of the process.

For example, the simple script below calculates the total swap usage of the process which PID = 1027:

# echo $((`grep Swap /proc/1027/smaps | awk '{ print $2; }' | tr '\n' '+'`0))

For UEK2(2.6.39) or later kernels

It is easier to check the swap usage of a specific process, just check “VmSwap” column in /proc/[PID]/status. This indicates the total usage of the swap space as one value. This column does not exist in /proc/[PID]/status with kernel < 2.6.39. For example, for sorting processes with the swap usage from larger, run a script below:

# for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | more

The value which is shown/calculated in this post does not indicate an accurate size of used swap space but just indicates rough approximate one. Some (like the shared library) could be double counted, and others(like swap cache) are not really swapped.

Filed Under: Linux

Some more articles you might also be interested in …

  1. acountry Command Examples in Linux
  2. pdfxup Command Examples in Linux
  3. kscreen-console Command Examples in Linux
  4. Permissions 0644 for ‘/home/username/.ssh/your_pem_file.pem:’ are too open
  5. gnome-software: command not found
  6. How to control resource (cgroup) with systemd for user process group in CentOS/RHEL 7
  7. arpspoof: command not found
  8. How to send Audit Logs to Remote Rsyslog Server in CentOS/RHEL 6,7
  9. po4a-gettextize Command Examples in Linux
  10. How to Configure an NFSv4-only Client using nfsconf in CentOS/RHEL 8

You May Also Like

Primary Sidebar

Recent Posts

  • powertop Command Examples in Linux
  • powertop: command not found
  • powerstat: command not found
  • powerstat Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright