Fixing Tmux Hangs - A Quick Guide

Hero image
Rocktim Saikia/2 min read

Recently I encountered a very strange issue with tmux on an Ubuntu EC2 instance. I was unable to create, attach to, list, or kill any tmux sessions. Any command starting with tmux was freezing the whole system. So I spent some time and found the following solution to the problem.

Terminating Stuck tmux Processes

When tmux hangs, your best initial approach is to terminate the unresponsive processes.

  1. Identify the Process: Use pgrep tmux to list all running tmux processes. This will display the PIDs (process IDs) of active tmux sessions. Better yet, use ps aux | grep tmux to list all running tmux processes with their associated command lines. This will help you identify the problematic session.

  2. Terminate Specific Processes: If you know the PID of a problematic session:

    • Gently terminate: kill [PID]
    • Forceful termination: kill -9 [PID]
  3. Terminate All tmux Processes: If you want to end all active tmux processes:

    • Gently terminate all: pkill tmux
    • Forceful termination of all: pkill -9 tmux

Remember, using the -9 option or SIGKILL signal leads to an immediate termination, bypassing the process's usual shutdown routine. This can be effective for hanging processes, but it doesn't allow the process any opportunity for cleanup. As always, when troubleshooting, ensure backups of important data and configurations are available.