Skip to content

Instantly share code, notes, and snippets.

@ichizok
Last active March 19, 2021 03:06
Show Gist options
  • Select an option

  • Save ichizok/a78fe6da1fc41e532e3f40cbac4a1036 to your computer and use it in GitHub Desktop.

Select an option

Save ichizok/a78fe6da1fc41e532e3f40cbac4a1036 to your computer and use it in GitHub Desktop.
Watch VmRSS
#!/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