Last active
January 11, 2022 11:52
-
-
Save kou1okada/ec084b00f78a2125377fff542f88f4b1 to your computer and use it in GitHub Desktop.
vmps.sh - Report virtual memory status of a process.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# vmps.sh - Report virtual memory status of a process. | |
# Copyright (c) 2019 Koichi OKADA. All right reserved. | |
# This script distributed under the MIT license. | |
# | |
function vmps () # <pid> [<delay>] | |
# Report virtual memory status of a process. | |
# Args: | |
# <pid> : Process ID | |
# <delay> : The delay between updates in seconds. | |
# If delay is not specified, only one report will be printed. | |
{ | |
local i=0 | |
local cmdline | |
shopt -s checkwinsize | |
[ -e "/proc/$1" ] && sed -e 's/\x00/ /g' "/proc/$1/cmdline" | |
while [ -e "/proc/$1" ]; do | |
awk -v header="$i" ' | |
/^Vm/ { | |
hdr=sprintf("%s%-10s", hdr, $1); | |
mem=sprintf("%s%8d%s", mem, $2,$3); | |
} | |
END{ | |
if(header==0) print hdr; | |
print mem; | |
} | |
' /proc/$1/status | |
let "i=(i+1)%(LINES-1)" | |
[[ -n "$2" ]] && sleep "$2" || break | |
done | |
} | |
[ "$(readlink -f -- "$0")" = "$(readlink -f -- "$BASH_SOURCE")" ] && { | |
cat <<-EOD | |
Usage: | |
source ${0##*/} | |
$(grep ^function -A5 "$0" \ | |
| sed -re 's/^function\s+(\w*)\s*\(\)\s*#\s*(.*)/\1 \2/g;s/^/ /g') | |
EOD | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment