Hello All,

I Am forking child processes. I am waiting for them to finish in parent. If you see my code What I want to parent is not to move forward until it get info from each child. Next portion of the code is dependent on the status of the child. I want to do kind of wait in a loop in parent and keep checking for the child's response. Here is my problem I am not able to do it last logic. Please help me with suggestions.

#!/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 D +EPENDS ON EACH RESULT FURTHER PROCESSING. WAIT IN A LOOP OR SOMTETHIN +G # NOT GETTING IT HOW TO DO IT. I DON'T WANT TO CONTINUE UNLESS I GET A +LL KIDS STATUS. DON'T WANT TO GO TO END DB MAIN UNLESS I GET ALL CHIL +D 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";

In reply to How to make parent wait for all the child processes. by gjoshi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.