Skip to content

Instantly share code, notes, and snippets.

@astrada
Created April 25, 2017 14:51
Show Gist options
  • Save astrada/b588ef6de5a721ed44b508195152add0 to your computer and use it in GitHub Desktop.
Save astrada/b588ef6de5a721ed44b508195152add0 to your computer and use it in GitHub Desktop.
#!/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