Skip to content

Instantly share code, notes, and snippets.

@MihaelIsaev
Forked from pyrtsa/throttle-SourceKitService
Created February 13, 2017 16:15
Show Gist options
  • Save MihaelIsaev/09492ad36ec8427fda786bdc4e12c147 to your computer and use it in GitHub Desktop.
Save MihaelIsaev/09492ad36ec8427fda786bdc4e12c147 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