# constants
#-----------------------------------------------------------------
$cd_dev = "/dev/cdrom"
+$children = Hash.new
#-----------------------------------------------------------------
# functions
# cdparanoia always outputs to cdda.wav
FileUtils.mv("cdda.wav", track.wav_file_name, $fu_args)
- # TODO: if there are more than N processes, wait for one of them to terminate
+ # If there are too many processes, wait for one of them to terminate
+ if ($children.keys.length > $opts.max_children) then
+ pid = Process.wait(-1)
+ $children.delete(pid)
+ end
+
pid = Process.fork
if (pid == nil) then
begin
rescue
Kernel.exit(1)
end
+ else
+ $children[pid] = 1
end
end
def self.parse(args)
opts = OpenStruct.new
opts.dry_run = false
+ opts.max_children = 4
$fu_args = { :verbose => true }
# Fill in opts values
opts.manifest_file = file
opts.partial = true
end
+ myparser.on("--max-children [NCHILD]", "-j",
+ "The maximum number of child processes to allow at any \
+given time") do |nchild|
+ opts.max_children = nchild.to_i
+ if (opts.max_children < 1) then
+ raise "can't set max_children to #{opts.max_children}"
+ end
+ end
end
parser.parse!(args)
next unless @t.has_key?(tnum)
audiorip(tnum, @t[tnum])
end
+ Process.waitall
end
def inspect
num_tracks = get_number_of_tracks_on_cd()
puts "found #{num_tracks} tracks"
manifest.rip(num_tracks)
+puts "*** FINISHED ***"
exit 0