libjsig
does not help, because SIGCHLD
handler is installed by libjava
, not by JVM itself.
sigaction(SIGCHLD, ...)
with sa_handler = SIG_DFL
is called only once by Java Class Library in the static initializer of java.lang.UNIXProcess.
Now you have the following options to work-around this.
The easiest one. Just install your signal handler after initialization of
java.lang.UNIXProcess
.Create your own
LD_PRELOAD
hook that will interceptsigaction
and ignore it when called withSIGCHLD
andSIG_DFL
arguments:
E.g.
#define _GNU_SOURCE
#include <signal.h>
#include <dlfcn.h>
#include <stddef.h>
int sigaction(int signum, const struct sigaction* act, struct sigaction* oldact) {
static int (*real_sa)(int, const struct sigaction*, struct sigaction*) = NULL;
if (signum == SIGCHLD && act->sa_handler == SIG_DFL) {
return 0;
}
if (real_sa == NULL) {
real_sa = dlsym(RTLD_NEXT, "sigaction");
}
return real_sa(signum, act, oldact);
}