Kill your zombie SSH sessions with a custom shell function

Environment & Shell Customization (Aliases/Functions/.Bashrc)

Kill your zombie SSH sessions with a custom shell function

🧩 The Challenge

You finally kill a hung background job, but your shell is still acting like it’s stuck in a loop or some ghost process is holding onto your terminal. I’ve spent way too long hunting for PID leftovers that just won’t die.

💡 The Fix

A small function in your bashrc that cleans up orphaned processes attached to your current TTY saves you from rebooting or manually grepping through ps output. It’s quick, dirty, and works every single time.

killtty() {
pkill -t $(tty | sed 's|/dev/||')
}

⚙️ Why It Works

By grabbing your current terminal device path via tty and stripping the dev prefix, the function tells pkill exactly which processes are tethered to your specific shell window. It cuts through the noise of system-wide processes and zaps only what’s running in your immediate view.

🚀 Pro-Tip: Alias this to ktty if you’re feeling lazy; your muscle memory will thank you during a production outage.

Linux Tips & Tricks | © ngelinux.com | 9/24/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted