U.Nakamura wrote:
> Hello,
> 
> In message "Kill support on Win32"
>     on May.15,2003 05:57:10, <djberge / qwest.com> wrote:
> | I would like to see Process.kill support added for Win32.  I've written a
> | module that does this (sys-win32process), but I would like to see it added
> | to the core.  Quick synopsis:
> 
> Ruby 1.8 already has `kill' support.
> Aren't you satisfied with it?
> 
> Current `kill' feature is:
> |  kill 0      -> Test to see if process is running, don't kill
> same.
> |  kill 1, 4-8 -> Nice kill
> cause `Errno::EINVAL'.
> |  kill 2      -> Send Ctrl+Break (console only)
> send Ctrl+C.
> |  kill 3      -> Send Ctrl+C (console only)
> cause `Errno::EINVAL'.
> |  kill 9      -> Hard kill
> same.
> 
> 
> I can't judge the behavior of signal 1, 4-8.
> Why did you determine such?
> 
> 

Actually, I didn't see this before, but I think my approach still has 
some merit, because the CreateRemoteThread() + ExitProcess() approach 
that I use for signals 1, 4-8 is safer.  From the msdn.com API reference 
on TerminateProcess():

"The TerminateProcess function is used to unconditionally cause a 
process to exit. Use it only in extreme circumstances. The state of 
global data maintained by dynamic-link libraries (DLLs) may be 
compromised if TerminateProcess."

This is why I chose only signal 9 to call TerminateProcess() and most 
others to use CreateRemoteThread() + ExitProcess().  Again, from the 
msdn.com API reference on ExitProcess():

"ExitProcess is the preferred method of ending a process. This function 
provides a clean process shutdown. This includes calling the entry-point 
function of all attached dynamic-link libraries (DLLs) with a value 
indicating that the process is detaching from the DLL. If a process 
terminates by calling TerminateProcess, the DLLs that the process is 
attached to are not notified of the process termination."

I chose signals 2 and 3 to represent SIGINT (Ctrl-C) and SIGQUIT 
(Ctrl-Break) because most *nix systems have SIGINT and SIGQUIT listed as 
#2 and #3 with a "kill -l".  It was an arbitrary decision on my part, 
but not one that I'm attached to - if you want to change it or remove 
it, I would not object.

Regards,

Dan