Le 12/02/2013 19:31, Jiri Kremser a écrit :
> BTW, the reason for Ctrl-C killing all processes is that the
signal
> is sent to all processes in the same group.
We implement it manually in the AgentShutdownHook.interruptAllThreads().
if there is a way to limit the signal to only getting sent to the
> agent process (and not its child processes such that the child
> processes remain alive and running even after the parent process
> (the agent) dies), then that is something we should look into. I
> didn't think it was possible to do that, but if so, that would be
> great.
The problem here is that on the one hand we need to send SIGINT to the agent to clear its
resources, on the other hand we don't want to send the SIGINT to the angent, because
he will relay it to the all daemon threads (including the running standalone.sh (run by
Java runtime)). So it is obviously contradictory. Something like "trap 'kill -9
myPid' INT" in the rhq.agent.sh would work, but it wouldn't clear the
resources.
The only way, I am aware of, is using the & operator:
"nohup ./rhq-agent.sh --daemon &" works well
"./run-in-background.sh ./standalone.sh" works well
or "Runtime.exec("standalone.sh &")" works well
check the att., I did a sequence diagram for it, because it is quite complex.
jk
Jiri,
I don't get it.
As far as I know, the child processes we create with Runtime.exec have
no link with internal JVM threads. The AgentShutdownHook is executed
when the JVM goes down, no matter if we run the agent in the foreground
or in the background with the wrapper script.
And we're not sending SINGINT signals to child processes by calling
interrupt on the parent JVM threads.
Runtime.exec internals are a fork/exec mechanism. Child processes
created like this get the process group (PGID) of their parent.
In our case, the rhq-agent.sh script is run in the foreground of an
interactive shell. So when you hit Ctrl-C, it's the interactive shell
that sends the SIGINT signal to all processes of the group the
foreground process belongs to.
Thomas