Hi Monks,
I have a rather annoying problem. I have an array that has a list of iso images that needs burning. I have a machine with 3xCDRW in it. I need to start all 3 CDRW simultaneously, toast the first 3 discs, then toast the reaminig discs in the array. Here is my code.
please excuse my code, I am not an esteemed parallel programmer
#!/bin/perl -w
use Fcntl qw/F_SETFL O_NONBLOCK O_ASYNC/;
my @fhs;
$SIG{IO} = sub {
foreach my $fh (@fhs) {
while (<$fh>) {
print ("I got $_ from $fh");
}
}
};
$SIG{CHLD} = 'DEFAULT';
print ("Saved discs:<br/>\n");
my @sortdiscs = sort(@discs);
my ($cut,$total,$pcntCut);
sub burnEm {
my ($disc,$writer)=@_;
my ($pid, $fh);
print (" $disc is being BURNED\n");
my @cdrecCmd=(["cdrecord", "-dummy", "-immed", "-eject", "-v", "gra
+cetime=2", "-tao", "dev=$writer", "$distroDirs{$distro}/$disc"]);
foreach my $cmd (@cdrecCmd) {
$pid = open($fh,'-|', "@$cmd") or die "Sorry could not fork cdrec
+ord program";
fcntl $fh, F_SETFL, O_NONBLOCK|O_ASYNC;
push (@fhs, $fh);
}
}
while ( @sortdiscs ) {
print ("\n\tSortDiscs Array:@sortdiscs:\n");
($discA,$discB,$discC,@remainingDiscs) = @sortdiscs;
if (defined $discA) {
burnEm($discA,"cdrw0");
if ( defined $discB ) {
burnEm($discB,"cdrw1");
if ( defined $discC ) {
burnEm($discC,"cdrw2");
}
}
}
@sortdiscs = @remainingDiscs;
}
Now the fundamental problems are:
1) I have hacked around with this code somewhat and I just can't get it to work.
2) The first 3 CD's don't complete toasting before the child processes starts cutting the next 3. I need to wait for each one to complete before starting the next set.
Nothingmuch helped me quite a bit already, and this is some of his/her code, but I am a bit stumped as to why it will not work as I expect it. I essentially know the reason, but I cannot get there.
Any, and I mean
ANY help will be appreciated.
Thanks
Hamish
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.