Skip to content

Instantly share code, notes, and snippets.

@terhechte
Created August 11, 2017 17:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terhechte/82a03a4615a711df543b3c523dd4ae69 to your computer and use it in GitHub Desktop.
Save terhechte/82a03a4615a711df543b3c523dd4ae69 to your computer and use it in GitHub Desktop.
Kill sourcekit if it consumes more than N amount of memory
#!/bin/bash
while true; do
fields=`ps aux -m | head | grep -i sourcekitd | tr -s ' '`
mem=`echo $fields | cut -d ' ' -s -f 6| awk '{$1=$1/1024; print $1;}' | cut -d '.' -f 1`
pid=`echo $fields | cut -d ' ' -s -f 2`
# how much mem before we're killing it. default 5000
if [ "$mem" -gt 5000 ]; then
echo "Killing sourcekitservice pid $pid with mem $mem"
kill -9 $pid
sleep 5
fi
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment