summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>2000-03-01 03:04:54 +0000
committerGurusamy Sarathy <gsar@cpan.org>2000-03-01 03:04:54 +0000
commit42b8b86c2abf1140ff5c8d74d48d4ece7deb56d7 (patch)
tree0ce11a1fcd5e2aecf881cc009d2fb14e55069de8
parent8e858c0b3848dae7efc722f353d7f17ce1333a30 (diff)
downloadperl-42b8b86c2abf1140ff5c8d74d48d4ece7deb56d7.tar.gz
support kill(0,$pid) on Windows to test if process exists
p4raw-id: //depot/perl@5386
-rw-r--r--README.win326
-rw-r--r--pod/perldelta.pod3
-rw-r--r--pod/perlport.pod5
-rw-r--r--win32/win32.c14
4 files changed, 20 insertions, 8 deletions
diff --git a/README.win32 b/README.win32
index 5499d3a4f4..830e129d7d 100644
--- a/README.win32
+++ b/README.win32
@@ -679,9 +679,9 @@ C<kill()> is implemented, but doesn't have the semantics of
C<raise()>, i.e. it doesn't send a signal to the identified process
like it does on Unix platforms. Instead it immediately calls
C<TerminateProcess(process,signal)>. Thus the signal argument is
-used to set the exit-status of the terminated process. In particular,
-C<kill(0,$pid)> 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 205365eb53..7345727f45 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<kill(0, $pid)> can now be used to
+test whether a process exists.
+
The C<Shell> module is supported.
Rudimentary support for building under command.com in Windows 95
diff --git a/pod/perlport.pod b/pod/perlport.pod
index 3009780ada..b062b3b106 100644
--- a/pod/perlport.pod
+++ b/pod/perlport.pod
@@ -1459,8 +1459,9 @@ Available only for socket handles. (S<RISC OS>)
Not implemented, hence not useful for taint checking. (S<Mac OS>,
S<RISC OS>)
-Unlike Unix platforms, C<kill(0, $pid)> will actually terminate
-the process. (Win32)
+C<kill($sig, $pid)> 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 4a7f091797..54f0455851 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;
+ }
}
}
}