diff options
author | Brian Clarke <clarke@appliedmeta.com> | 2000-07-28 11:18:29 -0400 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2000-08-01 01:13:33 +0000 |
commit | 2f67576d8cb103df532c921ad5e6caa4f7927a88 (patch) | |
tree | 12ec624666d4fe3c51d73b2d5647208e129845bd /win32 | |
parent | d897a58d2e5e1e3d2a32d03885d609925ad305e4 (diff) | |
download | perl-2f67576d8cb103df532c921ad5e6caa4f7927a88.tar.gz |
fix and question re: waitpid() under win32
Message-ID: <3981DC85.290314EB@appliedmeta.com>
Slightly reformatted and WNOHANG # define moved to win32.h
so that also POSIX.xs sees it, as suggsted by Sarathy.
p4raw-id: //depot/perl@6472
Diffstat (limited to 'win32')
-rw-r--r-- | win32/win32.c | 32 | ||||
-rw-r--r-- | win32/win32.h | 4 |
2 files changed, 24 insertions, 12 deletions
diff --git a/win32/win32.c b/win32/win32.c index 60777fa36f..3c3d1e56e7 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -53,7 +53,6 @@ #else #include <utime.h> #endif - #ifdef __GNUC__ /* Mingw32 defaults to globing command line * So we turn it off like this: @@ -1645,8 +1644,12 @@ win32_waitpid(int pid, int *status, int flags) long child = find_pseudo_pid(-pid); if (child >= 0) { HANDLE hThread = w32_pseudo_child_handles[child]; - DWORD waitcode = WaitForSingleObject(hThread, INFINITE); - if (waitcode != WAIT_FAILED) { + DWORD timeout = (flags & WNOHANG) ? 0 : INFINITE; + DWORD waitcode = WaitForSingleObject(hThread, timeout); + if (waitcode == WAIT_TIMEOUT) { + return 0; + } + else if (waitcode != WAIT_FAILED) { if (GetExitCodeThread(hThread, &waitcode)) { *status = (int)((waitcode & 0xff) << 8); retval = (int)w32_pseudo_child_pids[child]; @@ -1663,15 +1666,20 @@ win32_waitpid(int pid, int *status, int flags) long child = find_pid(pid); if (child >= 0) { HANDLE hProcess = w32_child_handles[child]; - DWORD waitcode = WaitForSingleObject(hProcess, INFINITE); - if (waitcode != WAIT_FAILED) { - if (GetExitCodeProcess(hProcess, &waitcode)) { - *status = (int)((waitcode & 0xff) << 8); - retval = (int)w32_child_pids[child]; - remove_dead_process(child); - return retval; - } - } + DWORD timeout=(flags&WNOHANG)?0:INFINITE; + DWORD waitcode = WaitForSingleObject(hProcess, timeout); + if (waitcode == WAIT_TIMEOUT) { + { + return 0; + } + else if (waitcode != WAIT_FAILED) { + if (GetExitCodeProcess(hProcess, &waitcode)) { + *status = (int)((waitcode & 0xff) << 8); + retval = (int)w32_child_pids[child]; + remove_dead_process(child); + return retval; + } + } else errno = ECHILD; } diff --git a/win32/win32.h b/win32/win32.h index 2e5b0740dd..eb5ecd2971 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -492,5 +492,9 @@ struct interp_intern { */ #include "win32iop.h" +#ifndef WNOHANG +# define WNOHANG 1 +#endif + #endif /* _INC_WIN32_PERL5 */ |