Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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