in reply to waitpid and Windows

... but doesn't perform as expected in the Windows world.

That's a pretty poor description of the problem. What are you expecting and how does what you are seeing differ from that?

The non-blocking form of waitpid seems to work fine on my system:

use POSIX qw[ :sys_wait_h ];; $pid = open O, '| perl.exe -e"sleep 10; exit(123)"' or die $!;; print waitpid( $pid, &WNOHANG ) while sleep 1;; 0 0 0 0 0 0 0 4360 -1 -1 -1 Terminating on signal SIGINT(2)

So how is it "not performing as expected" for you?

Also, showing the open being used woudl be a good idea as that can influence things.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: waitpid and Windows
by jeffthewookiee (Sexton) on Jun 02, 2007 at 11:59 UTC
    It seems to hang on the waitpid() call instead of returning immediately and moving on to the next loop step.
      It seems to hang on the waitpid()

      It's not hanging - you're just not seeing the output.

      To see the output you'll need to run BrowserUK's code as perl -l script.pl. Alternatively, you could change the third line of the code to:
      print waitpid( $pid, &WNOHANG ), "\n" while sleep 1;;
      Cheers,
      Rob

      Did you try running the snippet I posted above?

      Here it is as a one-liner in case you couldn't see how to run it. (You'll need to enter it as a single line.)

      C:\test>perl -MPOSIX=:sys_wait_h -le"$pid=open O, q[perl -esleep(10)|];print waitpid $pid,&WNOHANG whil +e sleep 1" 0 0 0 0 0 0 0 0 0 3204 -1 -1 Terminating on signal SIGINT(2)

      You'll need ^C to terminate it. What results did you see?

      If you can eliminate your installation and platform as a source of the problem, then you might look more closely at your implementation. Maybe post a bit more code? Including the open as I requested?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.