跳到主內容

【shell】 找出目前誰使用swap

who_use_swap.sh


#!/bin/bash
for p in /proc/[0-9]*; do
  pid=${p##*/}
  swap=$(awk '/VmSwap:/ {print $2}' $p/status 2>/dev/null)
  comm=$(tr -d '\0' < $p/comm 2>/dev/null)
  [ -n "$swap" ] && [ "$swap" -gt 0 ] && printf "%10s KiB  pid=%s  %s\n" "$swap" "$pid" "$comm"
done | sort -nr | head -20