How to close a Process and having shutdown hooks called ?
rednaxelafx at gmail.com
Tue Mar 4 11:51:27 UTC 2014
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:
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
> 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>
> 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 :)
> Nicolas Le Picard
More information about the core-libs-dev