How to close a Process and having shutdown hooks called ?

Tue Mar 4 10:45:33 UTC 2014

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.
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>


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 :)


Nicolas Le Picard

More information about the core-libs-dev mailing list