The soft way to kill a process on windows to send a WM_CLOSE/WM_QUIT.
http://stackoverflow.com/questions/2055753/how-to-gracefully-terminate-a-process

Rémi


Le 10/11/2010 10:46, Andreas Kohn a écrit :
On Wed, 2010-11-10 at 06:02 +1000, David Holmes wrote:
Hi Andreas,

On 10/11/2010 5:31 AM, Andreas Kohn wrote:
there seems to be a difference in behavior between Process#destroy()
implementations on Windows and !Windows: on Windows TerminateProcess()
[1] is called, which gives the process no way to react or in any way
intercept the termination, while on Unix a simple SIGTERM is send which
the process can just decide to ignore. [2]

Is this intentional?
As I understand it: yes and no. :)

The problem is that neither version is necessarily what you always want.
SIGTERM is nice in that it allows the process to execute cleanup handlers
etc (such as an exec'ed JVM!) but I don't think Windows has an equivalent,
so we have to use TerminateProcess. On the flip side if SIGTERM fails we
have no way to really kill an errant process.

Thanks for the confirmation that this is an unfortunate leak of the OS
details into the java library. Looking through the bugdatabase I found
various related bugs now, so I did not file a new RFE just now:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4073195
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4333183
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6960070

What we really need is two destroy methods: one that tries to
terminate
nicely and one with "extrene prejudice". But again I'm not sure that Windows
would support that. I suppose we could also define the destroy() method to
try both approaches, if available, eg SIGTERM wait a while SIGKILL. But then
we need a way to specify "wait a while".
I think if you have the ability as API user to indicate to Process
whether it should "stop, please" or "die!" it would be perfectly enough.

Windows may not provide the APIs for the "please" part, but then again
this is as mentioned above and in the bugs very system specific, so
having the Windows implementation do nothing in the "please" case should
be fine, as this would be still classify as "best effort".

Windows:
Process#stop() {
   // nothing, windows doesn't do it
}
Process#destroy() {
   TerminateProcess();
}

Unix:
Process#stop() {
   kill(SIGTERM);
}
Process#destroy() {
   kill(SIGKILL);
}

Regards,
--
Andreas

David Holmes

I do prefer the Windows behavior, mainly because I do create processes
once in a while that simply fail to terminate due to bugs in their
implementation, and having Process#destroy() as a last, and terminal,
resort is very helpful to work-around those issues.

Regards,
--
Andreas

[1]
http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/d87c1c06bbf9/src/windows/native/java/lang/ProcessImpl_md.c
[2]
http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/d87c1c06bbf9/src/solaris/native/java/lang/UNIXProcess_md.c



Reply via email to