Hi Monks, So I have a conceptual question. I am wondering if there's a way that I can distinguish between different childs; is there a child number, like first child, second child etc? What I would like is, each time the parent spawns off a child it would also give the child some distinct number so the different childs can, say, look at different files. For example:
#!/usr/bin/perl @dirname; $dirname[0]="TestList1.log"; $dirname[1]="TestList2.log"; $dirname[2]="TestList3.log"; for(1..4) { my $pid = fork(); if ($pid) { # parent push(@childs, $pid); print "we are in the parent bus \n"; waitpid($pid,0); } elsif ($pid == 0) { # child # here I want to read a different file each child # so child 1 would read dirname[0] # so child 2 would read dirname[1] # so child 3 would read dirname[2] # and they would all do the same thing, # but on different files # something like: #$mm = @child array's element number open (filelist, @dirname[$mm]) || die "couldn't open the file!"; @filename; @filename = <filelist>; print "@filename \n"; sleep 5; exit(0); } else { die "couldn’t fork: $! \n"; } print "LAST IN FOR \n"; } print "AFTER FOR \n";
Thanks a lot! - cartmanofvan

In reply to fork : distinguish between different child? by Anonymous Monk

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.