Skip to content

Instantly share code, notes, and snippets.

@terhechte terhechte/sh

Created Aug 11, 2017
What would you like to do?
Kill sourcekit if it consumes more than N amount of memory
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
sleep 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.