perl中可以分叉的进程数是否有限制?

cpp*_*der 2 perl fork

我面临着一个奇怪的问题.分叉进程的增长不超过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;
    }
}
Run Code Online (Sandbox Code Playgroud)

产量

...
...
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
...
...
Run Code Online (Sandbox Code Playgroud)

gee*_*aur 5

Perl没有定义这样的限制,但大多数操作系统都这样做.用waitpid收获的孩子,或在类Unix系统中,你可以使用sigaction(从POSIX模块)忽略SIGCHLDSA_NOCLDWAIT标志使系统自动获得孩子.(Linux碰巧让你省略SA_NOCLDWAIT,但无论如何你都应该使用它.)