#!/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.
In reply to Net::SSH::Perl and fork hangs by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |