Skip to content

Instantly share code, notes, and snippets.

@arn4v
Last active January 28, 2026 16:06
Show Gist options
  • Select an option

  • Save arn4v/45c4ac141d1e48678a120ac084ba2b92 to your computer and use it in GitHub Desktop.

Select an option

Save arn4v/45c4ac141d1e48678a120ac084ba2b92 to your computer and use it in GitHub Desktop.

tsgo Memory Watcher

Kills tsgo if it exceeds 10GB RAM. Checks once per minute.

Setup

1. Create the watcher script

mkdir -p ~/bin
cat > ~/bin/tsgo-watcher.sh << 'SCRIPT'
#!/bin/bash
LIMIT_KB=$((10 * 1024 * 1024))  # 10GB in KB

echo "$(date): tsgo-watcher started (limit: 10GB)"

while true; do
    sleep 60
    pgrep -x tsgo | while read pid; do
        rss=$(ps -o rss= -p "$pid" 2>/dev/null | tr -d ' ')
        if [[ -n "$rss" && "$rss" -gt "$LIMIT_KB" ]]; then
            echo "$(date): Killing tsgo (PID $pid) - using $((rss / 1024))MB"
            kill -9 "$pid"
        fi
    done
done
SCRIPT
chmod +x ~/bin/tsgo-watcher.sh

2. Create the launchd plist

cat > ~/Library/LaunchAgents/local.tsgo-watcher.plist << PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>local.tsgo-watcher</string>
    <key>ProgramArguments</key>
    <array>
        <string>$HOME/bin/tsgo-watcher.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/tmp/tsgo-watcher.log</string>
    <key>StandardErrorPath</key>
    <string>/tmp/tsgo-watcher.log</string>
</dict>
</plist>
PLIST

3. Start the watcher

launchctl load ~/Library/LaunchAgents/local.tsgo-watcher.plist

Commands

Action Command
View logs tail -f /tmp/tsgo-watcher.log
Stop launchctl unload ~/Library/LaunchAgents/local.tsgo-watcher.plist
Start launchctl load ~/Library/LaunchAgents/local.tsgo-watcher.plist
Check status launchctl list | grep tsgo

Customization

Edit ~/bin/tsgo-watcher.sh:

  • Change LIMIT_KB for different memory threshold
  • Change sleep 60 for different check interval
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment