How to close a Process and having shutdown hooks called ?
Krystal Mok
rednaxelafx at gmail.com
Tue Mar 4 11:51:27 UTC 2014
Hi Nicolas,
Looks like a well discussed question. On Posix systems, SIGTERM should work
for you. That's the default signal sent by the 'kill' command on Linux.
e.g. please take a look here:
http://stackoverflow.com/questions/2541597/how-to-gracefully-handle-the-sigkill-signal-in-java
- Kris
On Tue, Mar 4, 2014 at 2:45 AM, LE PICARD NICOLAS
<N.LEPICARD at chu-tours.fr>wrote:
> Hello everyone !
>
> I looked for the answer in this list and did not find anything relevant.
>
> I don't know it it's possible to close a Process et call shutdown hooks
> automatically. I looked into the code and found it was not possible (in
> jdk7).
> When we call destroy() on a Process, it will call terminateProcess of
> ProcessImpl class.
> This link shows that a TerminateProcess < kills > the process and WH_CBT
> hooks are NOT called.
>
> http://msdn.microsoft.com/en-us/library/windows/desktop/ms686722(v=vs.85).aspx
> Calling exitProcess (instead of TeminateProcess) seems to be dangerous ...
> but I don't understand why (ok, dlls could be locked, but when you do a
> CTRL +C it calls an exitProcess... so what's the problem ???)
>
> So I ask < how can we close a process, with the hooks called ? >. My
> knowledge is way smaller than people on openjdk... so I hope someone has an
> answer or a workaround.
>
> Byte the way, I looked for sending signals (SIGINT for Windows, SIGKILL
> for linux etc) to close a process.
> Maybe I'm wrong, but a solution could be to add to ProcessImpl_md.c :
>
> #include <signal.h>
>
>
>
> JNIEXPORT jboolean JNICALL
>
> Java_java_lang_ProcessImpl_CloseHandleWithHooks(JNIEnv *env, jclass
> ignored, jlong handle)
>
> {
>
> raise(SIGINT) ;
>
> }
>
> I think,it will call an ExitProcess so ... dangerous or not ?
> Of course, we have to add also a function in ProcessImpl and make call
> available from Process through an abstract function like < close() >
>
>
> Any clever thoughts on this subject (I'm sure it is a common problem...) ?
> Thanks :)
>
>
> Regards.
>
> Nicolas Le Picard
>
>
More information about the core-libs-dev
mailing list