tech stuff.

Shells shells everywhere

leave a comment »

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

Written by Lee Verberne

2011-06-12 at 08:48

Posted in BSD

Tagged with ,

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: