#!/usr/local/bin/perl -w use strict; use warnings; use Net::Telnet; use IO::Socket::INET; my $IsParent = 1; my $ListenPort = 5000; my $PPID = $$; print "I am the only process.\n"; my @children_pids; for my $count (1..3){ my $child_pid = fork(); if ($child_pid) { # If I have a child PID, then I must be the parent push @children_pids, $child_pid; } else { # I am the child # close the sides of the pipes not used by the child my $end; local $SIG{HUP} = sub { $end = 1 }; my $Child_PID = $$; print "\n============================== \n"; print "CHILD's PID is: $Child_PID \n"; my $db1 = ConnectToServer('127.0.0.1',$ListenPort,60); local $SIG{HUP} = sub { $end = 1 }; #Do something and then write to DB as done WriteValueToDB('done',$db1,$Child_PID . '_Status'); until ($end) { #print "Sleep 1\n"; sleep 1; } print "============================== \n"; function2(); } } foreach my $child (@children_pids) { print "Parent: Waiting on $child\n"; sleep 5; waitpid($child, 0); } # HERE I WANT TO GET THE STATUS OF ALL THE KIDS BECAUSE FROM HERE IT DEPENDS ON EACH RESULT FURTHER PROCESSING. WAIT IN A LOOP OR SOMTETHING # NOT GETTING IT HOW TO DO IT. I DON'T WANT TO CONTINUE UNLESS I GET ALL KIDS STATUS. DON'T WANT TO GO TO END DB MAIN UNLESS I GET ALL CHILD PROCESSES STATUS. # my $localtime = localtime; # my $child_stat = ReadValue($child . '_Status',$dbmain); # accoding to the result in DB decide to kill it #print "$child CHILD STAT: $child_stat \n"; #kill HUP => $child; print "END DB MAIN: $dbmain \n"; KillServer($dbmain); print "All done.\n";