Last active
March 19, 2021 03:06
-
-
Save ichizok/a78fe6da1fc41e532e3f40cbac4a1036 to your computer and use it in GitHub Desktop.
Watch VmRSS
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
| #!/bin/bash | |
| usage_exit() { | |
| echo >&2 "Usage: ${0##*/} [-n interval] pid" | |
| exit $1 | |
| } | |
| interval=1 | |
| while getopts 'hn:' OPT; do | |
| case "${OPT}" in | |
| h) | |
| usage_exit | |
| ;; | |
| n) | |
| if ! [[ ${OPTARG} =~ ^[.0-9]*$ ]]; then | |
| usage_exit 1 | |
| fi | |
| interval=${OPTARG} | |
| ;; | |
| \?) | |
| usage_exit 1 | |
| ;; | |
| esac | |
| done | |
| shift $((OPTIND - 1)) | |
| pid=$1 | |
| if ! [[ ${pid} =~ ^[1-9][0-9]*$ ]]; then | |
| usage_exit 1 | |
| fi | |
| while true; do | |
| rss=$(ps -o rss= -p "${pid}") | |
| [[ $? -eq 0 ]] || exit 0 | |
| printf "%s % 9d kB\n" "$(date +'%F %T')" "${rss}" | |
| sleep "${interval}" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment