#!/usr/bin/perl # batch.pl use IO::Select; use IO::Pipe; my @list = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"); my $children = 5; my $counter = 0; my $size = @list; foreach (@list) { $counter++; if (($counter%$children) && ($counter != $size)) { push(@temp,$_); } else { push(@temp,$_); @batch = @temp; @temp = @blank; foreach (@batch) { my $pipe = IO::Pipe->new(); my $pid = fork; die "Bad Fork $!" unless defined $pid; if ($pid) { $pipe->reader(); # $select->add( $pipe ); } else { $pipe->writer(); $pipe->autoflush(1); &dosomething; exit; } } } } sub dosomething { sleep 15; print "$_\n"; }