N
news.hinet.net
When i fork 5 child ,then process will terminate correctly.
But if i fork 25 child to do the same process. The program
will not terminate correctly.
How to use fork correctly??
ps: OS(win2000)
========================================
use IO::Socket::INET;
foreach my $child ((0..25)) {
if (fork() == 0) {
$| = 1;
print "Child $child trying to connect\n";
my $sock = IO::Socket::INET->new("www.hinet.net:80")
or die "Could not create connection\n";
$header=<<"ENDSTR";
GET / HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword,
application/x-shockwave-flash, */*
Accept-Language: zh-tw
Accept-Encoding: gzip
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Q312461)
Connection: close
ENDSTR
print $sock "$header";
@res=<$sock>;
open (handle,">$child");
print handle join('',@res);
close(handle);
$sock->close;
#print "Child $child exiting\n";
exit 0;
}
}
wait foreach ((0..25));
print "Parent exiting\n";
exit 0;
But if i fork 25 child to do the same process. The program
will not terminate correctly.
How to use fork correctly??
ps: OS(win2000)
========================================
use IO::Socket::INET;
foreach my $child ((0..25)) {
if (fork() == 0) {
$| = 1;
print "Child $child trying to connect\n";
my $sock = IO::Socket::INET->new("www.hinet.net:80")
or die "Could not create connection\n";
$header=<<"ENDSTR";
GET / HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword,
application/x-shockwave-flash, */*
Accept-Language: zh-tw
Accept-Encoding: gzip
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Q312461)
Connection: close
ENDSTR
print $sock "$header";
@res=<$sock>;
open (handle,">$child");
print handle join('',@res);
close(handle);
$sock->close;
#print "Child $child exiting\n";
exit 0;
}
}
wait foreach ((0..25));
print "Parent exiting\n";
exit 0;