use FileHandle ; package CommandList ; use ProcessMgr ; our(@ISA) = ProcessMgr ; sub new { my($name) = shift ; my($self) = new ProcessMgr(@_) ; bless $self => $name ; return $self ; } sub addCommands { my($self) = shift ; push @{$self->{'command_list'}}, @_ ; } sub nextProcess { my($self) = @_ ; my($cmd) = shift @{$self->{'command_list'}} ; return (undef, undef, undef) if( !$cmd ) ; my($pid, $h) ; $h = new FileHandle() ; $pid = open $h, "$cmd |" ; return ($pid, $h) ; } sub OnChildDone { my($self, $pid, $status, $outh, $userData) = @_ ; printf("%4d done status = %d\n", $pid, $status) ; } 1 ; package main ; my($mgr) = new CommandList(-max_processes => 2, # ) ; $mgr->addCommands("echo 1", "sleep 3", "echo 2", "sleep 10", "ls") ; $mgr->run ; print "done\n" ;