- 论坛徽章:
- 0
|
fork并发子进程为何总是2的n次方,我的本意是forkn个子进程的
多谢apile,我修改如下:
[code][/code]
#!/usr/bin/perl
use IO::Socket;
use POSIX;
die "Usage 0 num" if @ARGV<1;
$SIG{CHLD}=sub{ while (waitpid(-1,WNOHANG)>;0) {} };
my $num=shift;
for(my $i=0;$i<$num;$i++){
defined(my $child=fork()) or die "Can't fork!\n";
if ($child==0) {
$sock=IO::Socket::INET->;new( PeerHost=>;'192.192.191.134',
PeerPort =>;12000,
Proto =>;'tcp')
or die "Can't connect socket @\n";
my $answer=<$sock>;;
print "$$:Answer is $answer\n";
close $sock;
}
}
但还是有2的n次方-1个子进程 |
|