Skip to content

Instantly share code, notes, and snippets.

@pyrtsa
Created July 26, 2016 07:46
Show Gist options
  • Save pyrtsa/8af2c7cdd34c5371b144cb86a21c8dba to your computer and use it in GitHub Desktop.
Save pyrtsa/8af2c7cdd34c5371b144cb86a21c8dba to your computer and use it in GitHub Desktop.
Script to keep SourceKitService from eating up all OS resources
#!/bin/bash
limit="${1-10000000}";
echo "Keeping SourceKitService below $limit KiB of virtual memory."
echo "Hit ^C to quit."
while true; do
sleep 1;
p=`pgrep ^SourceKitService$`
if [ -n "$p" ]; then
vsz=`ps -o vsz -p "$p" | tail -1`
if [ $vsz -gt $limit ]; then
kill -9 "$p";
echo "`date +%H:%M:%S` Killed SourceKitService $p at $vsz KiB of virtual memory."
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment