in reply to Re: Re: Perl IPC: Checking Exit Status of Child Process
in thread Perl IPC: Checking Exit Status of Child Process

Just call fork() as many times as you need...
# Create 10 child processes for (1..10){ my $pid = fork(); last unless defined $pid; # Too many processes already? unless($pid){ # Child code here exit; } } # wait() for kids while(($pid = wait()) > 0){ # Check $? here }
--perlplexer

Replies are listed 'Best First'.
Re: Re: Re: Re: Perl IPC: Checking Exit Status of Child Process
by bayruds (Acolyte) on May 19, 2003 at 03:24 UTC
    Hi
    Thank you very much for replying back.

    When I fork in a loop, how do I ensure that all the child

    processes are executing concurrently. My main aim to use

    fork is to execute different subroutines in a cincurrent

    fashion. Many thanks for your help.
      fork() creates a new process, so, as long as you have enough CPU power, all fork()ed processes may be executing concurrently. I say "may be" because it really depends on what they do, on their priority in the system, and on the number of CPUs that the OS has at its disposal.

      --perlplexer