It was a mistake on my side . Semaphores are regulating the write access . I've included the sample code. Thanks for the replies wise ones.

#! /usr/bin/perl -w use strict ; use Socket; use IO::Handle; use IPC::Semaphore ; pipe(PARENTREAD, PARENTWRITE); PARENTWRITE->autoflush(1); my $sem=semget(&IPC_PRIVATE, 1, &IPC_CREAT | 0666) || die "semget: $!\ +n"; warn "semid= $sem\n"; semsign($sem); sub IPC_PRIVATE {0}; sub IPC_RMID {10}; sub IPC_CREAT {0001000}; sub GETVAL {5}; sub semwait { my $sem=shift; semop($sem, pack("s3", 0, -1, 0)) || die "semw: $!\n"; } sub semsign { my $sem=shift; semop($sem, pack("s3", 0, +1, 0)) || die "sems: $!\n"; } sub main () { my $msg ; print "I'm in the parent now \n"; for (my $count = 1 ; $count < 25 ; $count++ ) { my $child_pid = forker(); print "The child process had pid of $child_pid \n"; } my $count = 1 ; open (FH, '>>' , 'test.txt'); while ($msg = <PARENTREAD> ) { if ($msg =~ /PID/) { $count++ ; print "Increasing the count to $count \n"; print FH "$msg"; if($count == 24 ) { last ; } } } } sub forker() { #print " Child is forking \n" ; my $child_pid ; my $panic_monitor_pid ; if(!defined($child_pid = fork())) { print " Forking of child failed \n"; die "Dying abruptly\n"; }elsif($child_pid > 0) { print "In parent \n"; return $child_pid ; }else { #print "In child now \n The child had pid $$" ; $panic_monitor_pid = grandchild(); #print " The grand child has pid of $panic_monitor_pid \n"; exit ; } } sub grandchild () { my $child_pid ; my $panic_monitor_pid ; if(!defined($child_pid = fork())) { print " Forking of child failed \n"; die "Dying abruptly\n"; }elsif($child_pid > 0) { #print "In parent \n"; return $child_pid ; }else { semwait($sem); print PARENTWRITE "In the grandchild \n"; print PARENTWRITE "PID : The child had pid $$\n" ; semsign($sem); #$panic_monitor_pid = panic_monitor(); #print " The grand child has pid of $panic_monitor_pid \n"; exit ; } } main();

In reply to Re^2: Regulating write access to pipes using semaphores by girishatreya2005
in thread Regulating write access to pipes using semaphores by girishatreya2005

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.