watch is a very useful utility on Unix-like platforms, which can run a program periodically.

installation on macOS

It is not pre-installed on macOS, run following command to install:

brew install watch

example

The following command can monitor the memory usage (VSZ and RSS) of a process with PID 1107.

watch -d "ps aux | grep $USER | grep -v grep | grep 1107 | awk '{print \$5, \$6}'"

Option -d will highlight the changes between updates

usage

For more usage, please refer to:

watch -d
man 1 watch