Shells shells everywhere
tmux makes it easy to construct a plethora of ssh connections via tmux neww "ssh $HOST"
, so I find myself frequently doing this from scripts. tmux uses a shell to execute the ssh command, though, and I never liked how it left idle shells littering my process tree thusly:
\-+= 23132 user tmux: server (/tmp/tmux-505/default) (tmux) |-+= 25189 user sh -c sh | \--- 01613 user ssh hostA |-+= 08778 user sh -c sh | \--- 03665 user ssh hostB
Recently I actually bumped into my process limit and couldn’t spawn any new windows. This turned out to be pretty solve, though. I couldn’t figure out how to convince tmux not to use a shell to execute the command, but we can at least replace that shell process by telling the shell to exec rather than fork/exec. Now my script looks like this, and my process tree is nice and tidy.
let i=1 for host in $hosts; do tmux neww -d -n ${host%%.*} -t $session:$i "exec ssh $host" let i=i+1 done
Leave a Reply