Skip to content

Instantly share code, notes, and snippets.

@michaelneu
Created April 30, 2020 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelneu/644b5ac42b19ef9206155bcc25e10230 to your computer and use it in GitHub Desktop.
Save michaelneu/644b5ac42b19ef9206155bcc25e10230 to your computer and use it in GitHub Desktop.
vscode C++ tools keep hogging memory, even though IntelliSense is configured to 1GB. Start this script and get notified when it kills the language server, before your system gets unusable
#!/bin/bash
function warn {
i3-nagbar -t warning -m 'killed vscode cpp language server' > /dev/null
}
function kill_leak {
memory_leak=$(ps -eo pmem,pid,cmd | sort -k1 -nr | head -n1)
if [[ $memory_leak == *"cpptools-srv"* ]]; then
memory_usage=$(echo "$memory_leak" | awk '{print $1}')
memory_usage_critical=$(echo "$memory_usage > 20" | bc -l)
pid=$(echo "$memory_leak" | awk '{print $2}')
if [[ $memory_usage_critical != "0" ]]; then
kill -9 $pid
warn
fi
fi
}
while true; do
kill_leak
sleep 60s
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment