is there a tmux pre-command for when i run tmux kill session

Viewed 174

Suppose i have a tmux session with a process running like a docker container / wsgi server etc..

Is there a way to define a "process kill command" that will run before the tmux session is killed? I don't want any leftovers when the session has stopped.

2 Answers

You can use tmux hooks for this. Set the hook in your tmux.conf like this:

set-hook -g -n 'session-closed' 'run "<your command>"'

I am not sure you need it though. When tmux kill-session is run, all processes inside tmux will receive SIGHUP, so they should exit gracefully on their own.

If your process can be killed with Ctrl+c, a tmux plugin called tmux-safekill may do the trick.

Related