Created
April 30, 2020 20:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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