perlpal has asked for the wisdom of the Perl Monks concerning the following question:
My requirement is to initiate multiple perl scripts , each residing in a different directory, as independent processes on a WINDOWS(2008) system, simultaneously. I have attempted to implement this using fork in the Cygwin environment.However, i end up with sequential execution of scripts rather than the simultaneous execution required.
The code is mentioned below for reference :
#!C:\Perl\bin\perl.exe use warnings; use strict; my @drive_dir = ('perl /a/dir_file_create.txt' , 'perl /b/dir_file_cre +ate.txt', 'perl /c/dir_file_create.txt'); # Create a new process my $proc_cmd = fork(); if (!defined $proc_cmd) { die "Unable to fork: $!"; } elsif ($proc_cmd == 0){ # Child foreach my $create (@drive_dir){ exec ("$create"); } die "Unable to exec: $!" if $!; } else { # Parent print "\nThe process id is : $proc_cmd \n"; kill 9,$proc_cmd; wait(); print "Child exited with: ",$? >> 8,"\n"; }
Thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unable to emulate fork functionality on Windows
by Corion (Patriarch) on Mar 29, 2011 at 10:29 UTC | |
|
Re: Unable to emulate fork functionality on Windows
by BrowserUk (Patriarch) on Mar 29, 2011 at 11:32 UTC | |
|
Re: Unable to emulate fork functionality on Windows
by cavac (Prior) on Mar 29, 2011 at 11:10 UTC | |
|
Re: Unable to emulate fork functionality on Windows (spawn)
by tye (Sage) on Mar 29, 2011 at 17:12 UTC | |
|
Re: Unable to emulate fork functionality on Windows
by anonymized user 468275 (Curate) on Mar 29, 2011 at 15:55 UTC |