Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Thanks for all your replies. I should have mentioned that in my case child has been forked already and now I wish to communicate with specific. need Child to Child communication. kindly check the comment section below Suggestion for alternate approach is most welcome as well.

sub make_new_child { # Make new child... my $pid; my $sigset; # block signal for fork $sigset = POSIX::SigSet->new(SIGINT); sigprocmask(SIG_BLOCK, $sigset) or die "Can't block SIGINT for fork: $!\n"; die "fork: $!" unless defined ($pid = fork); if ($pid) { # Parent records the child's birth and returns. sigprocmask(SIG_UNBLOCK, $sigset) or die "Can't unblock SIGINT for fork: $!\n"; print "PID $pid\n" if $Debug; $children{$pid} = 1; $children++; return; } else { print "Child....\n" if $Debug; $SIG{INT} = 'DEFAULT'; # make SIGINT kill us as it did be +fore my $request = ""; # full long big request my $nreads = 0; # number of read loops my $tmout = 150; # timeout in second # unblock signals sigprocmask(SIG_UNBLOCK, $sigset) or die "Can't unblock SIGINT for fork: $!\n"; # handle connections until we've reached $MAX_CLIENTS_PER_CHIL +D for (my $i=0; $i < $MAX_CLIENTS_PER_CHILD; $i++) { # my $device=""; print "New connection....\n" if $Debug; my $client = $Socket->accept() or last; $client->autoflush(1); ($Debug && $client) ? print "Accepted....\n" : print "No S +ignal Recieved\n"; # do something with the connection my $sel = IO::Select->new($client); while ( $sel->can_read($tmout) ) { my $n = sysread($client, $request, 9999,length($re +quest)); last if ($n==0); $nreads++; my $display = ""; if ( $nreads == 0 ) { $display = '[timeout]'; } elsif ( length $request == 0 ) { $display = '[empty]'; } else { $display = $request; } $request=""; print "$display\n" if $Debug; my @data = split(/,/,$display); if($data[0] eq '!!'){ # A command #### ####Received the command here to send it t +o child PID 123 ###### child PID 123 has been already fork +ed and free ###### to serve this request print "A command, Lets send\n"; my $to_pid = $data[1]; my $command = $data[2];#__________________ +___________________________________________________ # # Lets send command to $to_pid from here #_________________________________________ +____________________________ # qx (echo e) print CHLD_IN "$command $pid sent from $p +id \n"; #print FHY ("OK, Lets Send coand\n"); sleep(3); } else { } } } exit(0); } }

In reply to Re: Child process inter communication by smarthacker67
in thread Child process inter communication by smarthacker67

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2023-10-04 12:55 GMT
Find Nodes?
    Voting Booth?

    No recent polls found