#!/bin/perl -w use strict; pipe(READER,WRITER); # used for communication between child and parent #$SIG{'CHLD'} = 'reaper'; # used for killing zombies my $zahl = 0; # number of currently running children my $zeile; # row my $pid; # process ID if (open FILE, "< /sls_backup/mdjanan/sleep.txt") { while($zeile = ) { if ($zahl < 4) { $zahl++; # increase number of children $pid = fork(); # a new child is born. yay :) print $pid."\n"; } if($pid == 0) { # child-process #close WRITER; # wait for command from parent while (my $line = ) { print "$line\n"; exec($line); # execute command } } else { #close READER; # send child a command sleep 1; print WRITER $zeile; if($zahl == 4) # four children are running. wait till one of them finishes. { while(! wait()) # *waiting* { } print "returncode ".$?."\n"; $zahl--; # decrease number of children } } } } else { print "\nCan't open file /sls_backup/mdjanan/sleep.txt\n"; } exit 0; # Waits for zombies #sub reaper #{ # wait(); # grab a zombie #} # sub reaper