From: Gurusamy Sarathy Date: Wed, 1 Mar 2000 03:04:54 +0000 (+0000) Subject: support kill(0,$pid) on Windows to test if process exists X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=42b8b86c2abf1140ff5c8d74d48d4ece7deb56d7;p=p5sagit%2Fp5-mst-13.2.git support kill(0,$pid) on Windows to test if process exists p4raw-id: //depot/perl@5386 --- diff --git a/README.win32 b/README.win32 index 5499d3a..830e129 100644 --- a/README.win32 +++ b/README.win32 @@ -679,9 +679,9 @@ C is implemented, but doesn't have the semantics of C, i.e. it doesn't send a signal to the identified process like it does on Unix platforms. Instead it immediately calls C. Thus the signal argument is -used to set the exit-status of the terminated process. In particular, -C will kill the process identified by C<$pid> (unlike -on Unix). This behavior may change in future. +used to set the exit-status of the terminated process. However, +a signal of 0 can be used to safely check if the specified process +exists, as on Unix. =item * diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 205365e..7345727 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -1287,6 +1287,9 @@ system(1,...) now returns true process IDs rather than process handles. kill() accepts any real process id, rather than strictly return values from system(1,...). +For better compatibility with Unix, C can now be used to +test whether a process exists. + The C module is supported. Rudimentary support for building under command.com in Windows 95 diff --git a/pod/perlport.pod b/pod/perlport.pod index 3009780..b062b3b 100644 --- a/pod/perlport.pod +++ b/pod/perlport.pod @@ -1459,8 +1459,9 @@ Available only for socket handles. (S) Not implemented, hence not useful for taint checking. (S, S) -Unlike Unix platforms, C will actually terminate -the process. (Win32) +C makes the process exit immediately with exit +status $sig. As in Unix, if $sig is 0 and the specified process exists, +it returns true without actually terminating it. (Win32) =item link OLDFILE,NEWFILE diff --git a/win32/win32.c b/win32/win32.c index 4a7f091..54f0455 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -989,6 +989,8 @@ win32_kill(int pid, int sig) /* it is a pseudo-forked child */ long child = find_pseudo_pid(-pid); if (child >= 0) { + if (!sig) + return 0; hProcess = w32_pseudo_child_handles[child]; if (TerminateThread(hProcess, sig)) { remove_dead_pseudo_process(child); @@ -1001,6 +1003,8 @@ win32_kill(int pid, int sig) { long child = find_pid(pid); if (child >= 0) { + if (!sig) + return 0; hProcess = w32_child_handles[child]; if (TerminateProcess(hProcess, sig)) { remove_dead_process(child); @@ -1009,9 +1013,13 @@ win32_kill(int pid, int sig) } else { hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid); - if (hProcess && TerminateProcess(hProcess, sig)) { - CloseHandle(hProcess); - return 0; + if (hProcess) { + if (!sig) + return 0; + if (TerminateProcess(hProcess, sig)) { + CloseHandle(hProcess); + return 0; + } } } }