in reply to Re^2: Execute progams in parallel
in thread Execute progams in parallel

How about something like:
#!/usr/bin/perl use strict; use warnings; use Proc::Background; use Config; my $secure_perl_path = $Config{perlpath}; if ($^O ne 'VMS') {$secure_perl_path .= $Config{_exe} unless $secure_perl_path =~ m/$Config{_exe}$/i }; my $command1 = "$secure_perl_path $ENV{'source'}/src/CreatePerson.pl"; my $command2 = "$secure_perl_path $ENV{'source'}/src/CreateCountry.pl" +; my @processes; foreach ( $command1, $command2 ) { my $proc = Proc::Background->new("$_ &"); push @processes, $proc; } while(1){ my $at_least_one_alive = 0; for my $proc(@processes){ if($proc->alive()){ print "'" . $proc->pid . "' is still alive"; $at_least_one_alive = 1; } sleep(1); #or however long you would like. } last if ! $at_least_one_alive; }

Replies are listed 'Best First'.
Re^4: Execute progams in parallel
by kalyanrajsista (Scribe) on Jan 25, 2010 at 12:11 UTC

    Is there any way that I can get the return value like success or failure of the process that is executed

      You can get the exit status using the wait method as described in the documentation for Proc::Background:

      wait

      Wait for the process to exit. Return the exit status of the command as returned by wait() on the system. To get the actual exit value, divide by 256 or right bit shift by 8, regardless of the operating system being used. If the process never existed, then return an empty list in a list context, an undefined value in a scalar context, or nothing in a void context. This function may be called multiple times even after the process has exited and it will return the same exit status.