Hello Monks,
Yesterday you all were very helpful with my question about
running parallel processes.
I got a working version with fork. But I can see the benefit of using the
Parallel::Jobs module. But I can't get it to work. I have 2 problems:
1. I can't get a simple sample to run in parallel. (See complete example below)
I'm trying to print "Middle" before "Hello... 10 seconds."
I tested this on an NT box. Using ActiveState perl 5.6
Main start
Hello. I want a nap.
Hello. I just slept 10 seconds.
Started hello: 2352
Middle: I'm impatient, so I will print now.
'1' is not recognized as an internal or external command,
operable program or batch file.
'1' is not recognized as an internal or external command,
operable program or batch file.
Started middle: 356
356, EXIT, 256
2352, EXIT, 256
Ciao. All the parallel parts are done.
Main end
2. I also don't understand the documentation's perl notation for sending the stdio/stderr to separate files.
Here is a snippet from the documentation:
$pid = Parallel::Jobs::start_job({ stdin_file => filename |
stdin_handle => *HANDLE,
stdout_handle => *HANDLE |
stdout_capture => 1,
stderr_handle => *HANDLE |
stderr_capture => 1 },
... cmd as above ...);
Could someone please explain? :)
In case it's important. I need a cross-platform solution (NT, Linux, Solaris) and using at least perl 5.6 on NT.
Here is the code:
#!/usr/bin/perl -w
use strict;
use Parallel::Jobs;
my($pid, $pid2);
print "Main start\n";
$pid = Parallel::Jobs::start_job(\&hello());
print "Started hello: $pid\n";
$pid2 = Parallel::Jobs::start_job(\&middle());
print "Started middle: $pid2\n";
my ($pid_new, $event, $data) = Parallel::Jobs::watch_jobs();
while(defined($event)) {
print "$pid_new, $event, $data\n";
($pid_new, $event, $data) = Parallel::Jobs::watch_jobs();
}
ciao();
print "Main end\n";
exit 0;
#################################
#subroutines
#################################
sub hello{
print "Hello. I want a nap.\n";
sleep(10);
print "Hello. I just slept 10 seconds.\n";
}
sub middle{
print "Middle: I'm impatient, so I will print now.\n";
}
sub ciao{
print "Ciao. All the parallel parts are done.\n";
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.