Parallel process in Perl

HI All,
I have scenerio where I need to call sub modules through for loop

for (i=0; i<8000 ;i++)
{
..
BLOCKA

}
BLOCKA
{
..
..
subroutine 1;
subroutine 2;
}
I want this to be run in parallel

process1 BLOCKA
{
...
...
subroutine 1;
subroutine 2;
}

process2 BLOCKA
{
....
....
subroutine 1;
subroutine 2;
}

Is there way in perl to do this .

I want to create 8000 process and want to run all the process in parallel

Thanks,
gvk

Hi gvk25,

Use fork() function.

Can you elobrate more ,I am bit new to perl scripting

Take a look to perlipc help page. There are several examples using fork().

It should be something similar to:

for (i=0; i<8000 ;i++) {
    my $child = fork();
    die qq[ERROR in fork() function\n] unless defined $child;
    next if $child != 0;

    ## Do job for the child...

    exit 0;
}
1 Like

I had a doubt on fork(),pls help me.

I can create only 4000 process on my machine .

I need to make 8000 process ,does the fork will wait for other process to complete and will create a new process on completion of that.

check the no. of processes a user can run? Its setup on the box / server. I am not sure about the parameter for that but i remember we used to set that limit to 4000 and if anyone tried to create new process would be rejected ... to check try logging on the box with this user in new session & let us know if that works, if there is a limit then it should fail. search google : maximum\ no.\ of\ processes\ +\ fork\ +\ perl - Google Search

Unless you have 8,000 processors, what is the advantage of running 8,000 processes?