use strict; use warnings; use IO::Select; use IO::File; use Data::Dumper; my @childs; foreach my $kid(qw(foo bar baz quux)) { # Create and gather child processes/fd's push @childs, child_labor($kid); } my @results; my @files_ready; my $file_iter = IO::Select->new(); $file_iter->add(@childs); while (@files_ready = $file_iter->can_read(1)) { for (@files_ready) { my $fd = shift @{$_}; my $child = shift @{$_}; chomp(my $data = <$fd>); if ($data) { push @results, [ split ":", $data ]; } sleep 10; } } # Printing some results... print Dumper(@results); sub child_labor { my $name = shift; my $fd; defined (my $pid = open $fd, "-|") # Indirect fork, read child stdout or die "Couldn't fork: $!"; # Parent... if ($pid) { return [ $fd, { pid => $pid, name => $name } ]; } # Child... else { $0 .= " $name"; my $counter = 0; while (1) { # Generate some output for our parent to read print "$name:" . 100 * (int(rand(100))+1) . "\n"; sleep int(rand(10)); last if $counter++ > 13; } # Important to exit from the child. exit 0; } } #### ioctl(6, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fff0f84f2f0) = -1 EINVAL (Invalid arg ument) lseek(6, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek) fcntl(6, F_SETFD, FD_CLOEXEC) = 0 select(8, [3 4 5 6], NULL, NULL, {1, 0}) = 1 (in [3], left {0, 999994}) read(3, "foo:7100\n", 8192) = 9 rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0 rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 nanosleep({10, 0}, 0x7fff0f84f7d0) = 0 close(3) = 0 rt_sigaction(SIGHUP, {SIG_IGN, [], SA_RESTORER, 0x7fdd25eb2030}, {SIG_DFL, [], 0 }, 8) = 0 rt_sigaction(SIGINT, {SIG_IGN, [], SA_RESTORER, 0x7fdd25eb2030}, {SIG_DFL, [], 0 }, 8) = 0 rt_sigaction(SIGQUIT, {SIG_IGN, [], SA_RESTORER, 0x7fdd25eb2030}, {SIG_DFL, [], 0}, 8) = 0 wait4(10129,