Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to do a nonblocking
waitpid()
with ActiveState's perl (v5.6.0) for win32?

I'm looking for the equivalent of
waitpid($pid,&POSIX::WNOHANG)
because I get "Your vendor has not defined POSIX macro WNOHANG, used at line..." when using that.
Thanks...

Replies are listed 'Best First'.
Re: win32 nonblocking waitpid()
by tye (Sage) on Jul 28, 2000 at 07:49 UTC

    I was surprised that this wasn't supported. I checked why, and it kinda sucks. The code for win32_waitpid() [which was written in order to port Perl] accepts a flags argument and just ignores it. And then it goes on to do:

    DWORD waitcode = WaitForSingleObject(hProcess, INFINITE);

    We need a simple patch that defines WNOHANG as 1 and then does:

    DWORD waittime= (WNOHANG&flags) ? 0 : INFINITE; DWORD waitcode = WaitForSingleObject(hProcess, INFINITE);

    I don't supposed you'd like to produce such a patch to save me the time, would you? Or at least report it to the perl5-porters.

RE: win32 nonblocking waitpid()
by Anonymous Monk on Jul 28, 2000 at 23:12 UTC
    NEVER MIND THE ABOVE! I managed to get ahold of VC++ and work out the patch.

    Of course, WNOHANG isn't defined under win32, so as a workaround for that I just
    #ifndef WNOHANG #define WNOHANG 1 #endif
    near the top of win32.c
    Of course you must also add the check(s) (there's a conditional compilation there) for the return val WAIT_TIMEOUT now, in addition to the check for WAIT_FAILED...

      Ah, but you need to put it in a *.h file that will be included by the Posix module so that it will know that your vendor now does define WNOWAIT.

      (short pause while I double check something before opening my big mouth -- something I almost never do)

      Posix.pm #include's perl.h which #include's config.h so the definition of WNOHANG needs to be added to each of the win32/config_H.* files except win32/config_h.PL.

      Thanks a ton for doing this!

Re: win32 nonblocking waitpid()
by Anonymous Monk on Jul 28, 2000 at 19:09 UTC
    Well, I reported this to the perl5-porters mailing list...
    Unfortunately I don't currently have access to any windows development tools (other than perl on a laptop, where I discovered this) as I generally use Linux for everything. Perhaps you should go ahead with the patch...or see if someone on p5p takes it up.

    Thanks...