I am looking to execute a function when a child tmux process is terminated.

Consider the following script:


function foo
  echo "foo exit"

trap foo SIGHUP


this script starts tmux. Then, from inside of the tmux session, I run:

$ tmux kill-session

tmux then closes, and I see:


The foo function isn't invoked, and I guess its because the parent process doesn't receive SIGHUP.

I am looking to execute the foo function when tmux is closed. How can I achieve this?


1 Answer 1


You need to replace the signal with SIGCHLD.

trap foo SIGCHLD

That signal gets sent to the parent if a forked child process stopped/terminated. While SIGHUP only affects the current process/script as you mentioned.

You must log in to answer this question.

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