J
Jacob Heider
I've been following clpm for some months now, so hopefully I'll be able
to do this in a way that doesn't offend anyone.
I'm trying to write a console-based replacement for Grip, a
CD-ripper/-encoder under linux. In theory, I should be able to encode
the wav files while ripping subsequent once, since the actual CD-ripping
is IO-bound. The obvious way (to me, at least) is to fork a child to do
the encoding, and tell subsequent children not to start working until
prior children finish. (I think) I know why this doesn't work, i.e. the
first child isn't a child of the second child, etc., so waitpid won't
work. I know there got to be a better way, and probably at least a
half-dozen ways which could work. Please help.
The code (excerpt) which doesn't work is (some lines split to get under
72-characters):
#!/usr/bin/perl
use warnings;
use strict;
my $lastpid;
for (my $i = 1; $i <= 5; $i++) {
system("cdda2wav -D /dev/cdrom -I cooked_ioctl -P 0 -t $i"
"-O wav -H -g $i.wav") == 0
or die "cdda2wav failed: $?\n";
my $childpid = fork;
die "fork failed: $?\n" unless defined($childpid);
if ($childpid == 0) {
if ($lastpid) {
waitpid($lastpid, 0);
}
system("lame -V 3 $i.wav $i.mp3") == 0
or die "lame failed: $?\n";
system("oggenc -q 3 -o $i.ogg $i.wav") == 0
or die "oggenc failed: $?\n";
system("flac -6 -o $i.flac $i.wav") == 0
or die "flac failed: $?\n";
system("rm $i.wav");
exit;
}
$lastpid = $childpid;
}
__END__
The system calls could be anything, of course, but these are the
applications I'm calling. I have looked a Parallel::ForkManager, but
since this project is to get me into perl from a primarily C background,
I'm trying to be thorough in exploring my options.
Someday I hope to wrap this baby in a quality curses GUI (since I'm sick
to death of non-text apps), but if I can get the guts to run, I'll be
most of the way towards having something useful.
Thanks for the help,
Jacob
to do this in a way that doesn't offend anyone.
I'm trying to write a console-based replacement for Grip, a
CD-ripper/-encoder under linux. In theory, I should be able to encode
the wav files while ripping subsequent once, since the actual CD-ripping
is IO-bound. The obvious way (to me, at least) is to fork a child to do
the encoding, and tell subsequent children not to start working until
prior children finish. (I think) I know why this doesn't work, i.e. the
first child isn't a child of the second child, etc., so waitpid won't
work. I know there got to be a better way, and probably at least a
half-dozen ways which could work. Please help.
The code (excerpt) which doesn't work is (some lines split to get under
72-characters):
#!/usr/bin/perl
use warnings;
use strict;
my $lastpid;
for (my $i = 1; $i <= 5; $i++) {
system("cdda2wav -D /dev/cdrom -I cooked_ioctl -P 0 -t $i"
"-O wav -H -g $i.wav") == 0
or die "cdda2wav failed: $?\n";
my $childpid = fork;
die "fork failed: $?\n" unless defined($childpid);
if ($childpid == 0) {
if ($lastpid) {
waitpid($lastpid, 0);
}
system("lame -V 3 $i.wav $i.mp3") == 0
or die "lame failed: $?\n";
system("oggenc -q 3 -o $i.ogg $i.wav") == 0
or die "oggenc failed: $?\n";
system("flac -6 -o $i.flac $i.wav") == 0
or die "flac failed: $?\n";
system("rm $i.wav");
exit;
}
$lastpid = $childpid;
}
__END__
The system calls could be anything, of course, but these are the
applications I'm calling. I have looked a Parallel::ForkManager, but
since this project is to get me into perl from a primarily C background,
I'm trying to be thorough in exploring my options.
Someday I hope to wrap this baby in a quality curses GUI (since I'm sick
to death of non-text apps), but if I can get the guts to run, I'll be
most of the way towards having something useful.
Thanks for the help,
Jacob