ssh hangs in forked children

This is a discussion on ssh hangs in forked children within the OpenSSH Development forums, part of the Networking and Network Related category; I have attempted to simultaneously ssh to a number of boxes (with openssh 3.5p1 - 3.9p1) via forking subprocesses. ...


Go Back   Usenet Forums > Networking and Network Related > OpenSSH Development

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-30-2008
nazrat
 
Posts: n/a
Default ssh hangs in forked children

I have attempted to simultaneously ssh to a number of boxes (with
openssh 3.5p1 - 3.9p1) via forking subprocesses. However, there always
seem to be a few ssh sessions got stuck and thus, my control (parent)
process cannot exit. I have searched for similar problems regarding
ssh hanging with fork, but most results indicated that the issue was
on the remote machine with an inappropriately demonized process (ie.
not redirect 3 input streams). In my scenerio, the forking doesn't
happen on remote site and the remote command is just a simple one
(uname) as demonstrated in the following scripts.
In this setting, I have an 'expect' script (spawn.exp) used to cache
the password and feed it to spawned processes (ssh.pl).

% ./spawn.exp ./ssh.pl

ssh.pl:

#!/usr/local/bin/perl -w
use strict;

my %pids;

for my $id ('01'..'05') {
my $pid = fork();
die "fork $id: $!\n" unless defined $pid;
if ($pid == 0) {
#open STDIN, '</dev/null';
#open STDOUT, '>/dev/null';
#open STDERR, '>/dev/null';
exec 'ssh', "build-$id", 'uname', '-a';
}
else {
$pids{$pid} = "build-$id";
}
}
while (%pids) {
my $pid = wait();
last if $pid == -1;
delete $pids{$pid} if exists $pids{$pid};
}

__END__


spawn.exp:

#!/usr/bin/expect --

set passwd ""
set timeout -1

eval spawn -noecho $argv
expect {
"Please try again." {
set passwd
exp_continue
}
"password:" {
if {$passwd == ""} {
stty -echo
send_user " (script) "
expect_user -re "(.*)\n"
stty echo
set passwd $expect_out(1,string)
} else {
send_user " (supplied by script) "
}
send -- "$passwd\r"
exp_continue
}
}
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:42 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0