ummm...according to "perldoc perlfunc" my parent/child comments aren't backwards.

Fork Does a fork(2) system call to create a new process running the same program at the same point. It returns the child pid to the parent process, `0' to the child process, or `undef' if the fork is unsuc­cessful.

In your code example you have

if (my $pid = fork()) { # a true or non-zero value for the parent # stuff } else { # a false value or 0 for the child # stuff }
Your logic is the same as mine.

I used system because that is what he was using, it makes it clearer (at least to me) how his example correlated to my solution. I also tend to leave out the extra error checking because it can cause one to miss the point of the example...and by that token, you're not checking to see if your fork failed. :)

To error test everything I guess the code would look like

foreach my $wks (@wkslist) { my $pid = fork; if (!defined($pid)) { die "fork failed: $!"; } elsif ($pid == 0) { # child print "rshing to $wks\n"; exec("$rsh_cmd $wks ls") || die "exec failed for $wks: $!"; } else { push(@pids,$pid); } } foreach my $pid (@pids) { waitpid($pid,0); if ($? != 0) { print "non zero exit from $pid: $?"; } }
give me a bit and I'll figure out how to make $? look pretty :)

/\/\averick
perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"


In reply to Re: Re: Re: Background process using a system call by maverick
in thread Background process using a system call by jalebie

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.