Those docs are just a bit confusing and I can see why rovf is concerned that waitpid would suspend his program.

First, the docs say that non-blocking wait is only available for "machines supporting either the waitpid(2) or wait4(2) system calls". Perhaps rovf's machine is one of the machines that doesn't?

Second, it isn't entirely clear how one would write a program to use a non-blocking wait, assuming there is one. The docs give an example of a while loop but the ellipsis in the example are placed above the loop, not within the loop. I'm guessing that one is expected to use a polling pattern, but if that were to be non-blocking, one would have to place one's application code inside the polling loop rather than above it. To avoid suspending your program I'm guessing the code should look something like this?

use POSIX ":sys_wait_h"; #... do { # ... do some stuff while waiting ... # check in to see if the process has ended ... $kid = waitpid(-1, WNOHANG); } while $kid > 0;

Best, beth


In reply to Re^2: Testing whether a process has finished by ELISHEVA
in thread Testing whether a process has finished by rovf

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.