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

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.



Solution 1:[1]

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.

Solution 2:[2]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 skowalak
Solution 2 Matt