I am starting a process in a tmux window in a terminal window. When I close the terminal window, the process not killing automatically but If I kill tmux window before close terminal window, the process killing. How can I kill related tmux window when the terminal window closed ?

Can we bind commands the close event of the terminal window ?

2 Answers 2


This is a bit of a hack but you could add this to your interactive shell configuration:

alias tmuxn='tmux new-session -s $$'
_trap_exit() { tmux kill-session -t $$; }
trap _trap_exit EXIT

Then you can use tmuxn to start a new session. The session will be named as your shell's PID. When your shell exits, the session will be killed.

  • Nice hack. It does the work. I didn't know that tmux didn't close session after closing and I had like 40 sessions in my server.
    – Raza
    Commented May 20, 2020 at 4:00

Maybe you can not.
For most people who use tmux, they usually close the terminal window instead of the tmux window in order to keep the process (ssh-client for example) running. And then, you can attach the origin tmux session in another terminal.
If you do not need this feature, you can use terminator instead of tmux. Terminator splits the terminal window itself. So, if you close the terminator window, you close everything running in that window. Nothing will be kept in the background.

  • I love tmux. I am opening tmux windows in a terminal window for related processes(more than one tmux window) and opening another terminal window for other works. So I am working with more than one terminal window at a time. Ok, than I will kill tmux windows or detach client before close terminal window. Commented Jul 23, 2013 at 2:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .