How to close a Process and having shutdown hooks called ? (original) (raw)
LE PICARD NICOLAS N.LEPICARD at chu-tours.fr
Tue Mar 4 10:45:33 UTC 2014
- Previous message: JDK 9 RFR of JDK-8035452: Fix serial lint warnings in core libs
- Next message: How to close a Process and having shutdown hooks called ?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: JDK 9 RFR of JDK-8035452: Fix serial lint warnings in core libs
- Next message: How to close a Process and having shutdown hooks called ?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]