in reply to Running perl scripts in parallel

Sure; simple mock up:
system('perl -w perlscript1.pl) if !fork; system('perl -w perlscript2.pl) if !fork;
See fork. Of course, the problem with the above is that I haven't done proper child reaping -- see perlipc. In your case, you may want to just set
$SIG{CHLD} = 'IGNORE';
before you invoke the forks. You'll also probably want to swap system to exec, since in the sample case you aren't waiting on a return value.

There's a lot of additional complexity, but this is the basic concept.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^2: Running perl scripts in parallel
by perl_help26 (Beadle) on Jul 23, 2014 at 15:52 UTC
    I have tried this but it still won't let me continue my original script i.e. in pseudo code:
    script1.pl ------------------------- call listener script2.pl #runs forever and outputs stuff call listener script3.pl #runs forever and outputs stuff die "Done script 1";

    I tried your method butb script1.pl still wouldn't die. It is stuck at calling the listeners Thanks

      Are you sure? If I'm understanding your comment, the only scenario where this should be true is if your fork is failing. What happens when you run this code:
      use strict; use warnings; my $pid = fork(); die "Fork failed" if not defined $pid; if ($pid) { #parent print "Parent output\n"; } else { #child exec q|perl -e 'sleep(1); print "Child output\n"'|; } wait; print "Parent finishing\n";

      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

        Actually, it's my bad ! it actually worked :) Thank u tons!