Skip to content

Instantly share code, notes, and snippets.

@MihaelIsaev
Forked from pyrtsa/throttle-SourceKitService
Created February 13, 2017 16:15

Revisions

  1. @pyrtsa pyrtsa created this gist Jul 26, 2016.
    16 changes: 16 additions & 0 deletions throttle-SourceKitService
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!/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