Skip to content

Instantly share code, notes, and snippets.

Last active Apr 12, 2019
What would you like to do?
Script to monitor the usage of CPU, memory by a process via `top`
# Usage: ./ <PID of the process>
# Output: top.dat with lines such as `1539689171 305m 2.0`, i.e. unix time - memory with m/g suffix - CPU load in %
# To plot the output, see
export PID=$1
rm top.dat
while true; do top -p $PID -bMn 1 | egrep '^ *[0-9]+' | awk -v now=$(date +%s.%N) '{print now,$6,$9}' >> top.dat; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment