I have an infinite while
loop bash script embedded in tmux status bar. In ~/.tmux/conf:
set -g status-right '... #(path/loop.sh) ...'
Tmux seems to run this script with sh -c
. After tmux started:
$ ps x | grep loop.sh
23433 pts/4 S+ 0:00 grep --color=auto loop.sh
31814 ? S 0:00 sh -c path/loop.sh
31818 ? S 0:00 /bin/bash path/loop.sh
tmux kill-session
terminates the sh -c
process. If I strace
it and kill the session:
$ strace -p 31814
strace: Process 31814 attached
wait4(-1, 0x7ffeacbfbf9c, 0, NULL) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
--- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=27643, si_uid=1000} ---
+++ killed by SIGTERM +++
But the subshell is left untouched because of the infinite loop:
$ ps x | grep loop.sh
2443 pts/4 S+ 0:00 grep --color=auto loop.sh
31818 ? S 0:00 /bin/bash path/loop.sh
Question
I want the subshell to be terminated automatically after the tmux session ends. Is there a way to do this, by changing tmux settings or handling SIGTERM
sent to the sh -c
process?
(Edit: tmux version is 2.8)