Created
April 25, 2017 14:51
-
-
Save astrada/b588ef6de5a721ed44b508195152add0 to your computer and use it in GitHub Desktop.
This file contains 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 | |
TARGET_FILE="/tmp/gdfuse.mem.log" | |
PROCESS_NAME=${1:-"google-drive-ocamlfuse"} | |
PID=$(ps -C "$PROCESS_NAME" -o pid=) | |
PID=${PID## } | |
if [[ -e "$TARGET_FILE" ]] | |
then | |
rm "$TARGET_FILE" | |
fi | |
if [[ -n "$PID" ]] | |
then | |
STATM="/proc/$PID/statm" | |
while [[ -e "$STATM" ]] | |
do | |
TIMESTAMP=$(date +%T) | |
STATM_CONTENT=$(cat "$STATM") | |
echo "[$TIMESTAMP] $STATM_CONTENT" >> $TARGET_FILE | |
sleep 5 | |
done | |
else | |
echo "Error: Cannot get $PROCESS_NAME PID" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment