Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/roadm/bin/perl use strict; use warnings; use Net::SSH::Perl; print "Starting main program\n"; my @childs; my $user = "root"; my $handle; my $host = "zeus-b001"; $handle = Net::SSH::Perl->new($host); $handle->login($user, $user); my $cmd = "sleep 1"; my $pid = fork(); if ($pid) { # parent push(@childs, $pid); print "child pid is [$pid]\n"; } elsif ($pid == 0) { # child my $ret = sub1($handle, $cmd); print "ret is $ret\n"; exit 0; } else { die "couldnt fork: $!\n"; } foreach my $pid (@childs) { my $tmp = waitpid($pid, 0); print "done with pid $tmp\n"; } # The program hangs here my ($out,$err, $exit) = $handle->cmd("uname -a"); print "End of main program\n"; sub sub1 { my ($handle,$cmd) = @_; print "started child process\n"; my ($out,$err,$exit) = $handle->cmd($cmd); print "done with child process\n"; return 1; }
The program hangs in the parent process at the stmt my ($out,$err, $exit) = $handle->cmd("uname -a"); If I comment out the "my ($out,$err,$exit) = $handle->cmd($cmd);" in the subroutine sub1(), then parent process do not hang. Is there a solution to this issue or am I doing something wrong? Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::SSH::Perl and fork hangs
by perlfan (Parson) on Jun 02, 2014 at 18:47 UTC | |
by arun_o_gupta (Initiate) on Jun 02, 2014 at 18:54 UTC | |
by Old_Gray_Bear (Bishop) on Jun 02, 2014 at 19:11 UTC | |
by Anonymous Monk on Jun 02, 2014 at 19:31 UTC | |
by salva (Canon) on Jun 02, 2014 at 19:10 UTC |