I am facing a weird problem. The forked processes is not increasing more than 64.
sub create_process()
{
my $child_pid;
my @nsitr;
my $i = 0;
foreach my $domain (@domains)
{
@nsitr = @nameservers;
open my $dnsfh, '>', $outputfile or die "Unable to open $outputfile - $!";
foreach my $ns (@nameservers)
{
print "Forking child $i\n";
defined($child_pid = fork() ) or (die "Unable to fork a new process" && next);
$i++;
if($child_pid == 0)
{
&resolve_dns($dnsfh, $domain, $ns);
exit;
}
}
close $dnsfh;
}
}
Output
...
...
Forking child 60
Forking child 61
Forking child 62
Forking child 63
Forking child 64
Forking child 64
Forking child 64
Forking child 64
Forking child 64
...
...
Perl doesn’t define such a limit, but most operating systems do. Use
waitpidto reap children, or on Unix-like systems you can usesigaction(from thePOSIXmodule) to ignoreSIGCHLDwith theSA_NOCLDWAITflag to have the system reap children automatically. (Linux happens to let you omitSA_NOCLDWAIT, but you should use it anyway.)