some questions about JVM shutdown

the scenario is like this:

i use Runtime.getRuntime().exec() to execute another sub-process.

When i press ctrl+c to terminate the program, the subprocess exit also

however if i use "kill -2" unix command to terminate the program, its subprocess do no exit with the program, i suppose the JVM reacts the same to a "kill -2" and a ctrl+c ?

anyone could explain to me, thanks

[404 byte] By [yslee4a] at [2007-10-3 3:32:02]
# 1

well I am not 100% sure of my response but here are some thinkings that could help finding the solution.

1) you should think of replacing "kill -2" by a more generic version like kill -INT or kill -KILL

2) the CTRL+C shortcut is configurable. so your administrator or even you can decide what signal must be send by perssing CTRL+C

3) in my opinion CTRL+C is equivalent to "kill -KILL" (but here I am not 100%sure) and "kill -2" is equivalent to "kill -INT". so in my opinion you are not sending the same signal to the process, so i am not surprised your are not having the same behavior.

Hope I helped

Marc

guerrinma at 2007-7-14 21:26:07 > top of Java-index,Java Essentials,Java Programming...
# 2
You could try kill-9 <pid>. . This should terminate the process.
karma-9a at 2007-7-14 21:26:07 > top of Java-index,Java Essentials,Java Programming...
# 3
More to the point, you could try not killing anything and providing proper means to shut your application down.
ejpa at 2007-7-14 21:26:07 > top of Java-index,Java Essentials,Java Programming...
# 4
that would be the best solution indeed.
guerrinma at 2007-7-14 21:26:07 > top of Java-index,Java Essentials,Java Programming...
# 5

> More to the point, you could try not killing anything

> and providing proper means to shut your application

> down.

yes, but seriously i need to do some cleanup if the program halts all of a sudden, so i need a sigterm, sigint, sigkill to test my program. I have added a shutdownhook to the main class, it can detect a sigint and sigkill, but the JVM helps me to automatically close all the subprocesses if i press ctrl+c but not when i use "kill -2" command, that is why i am asking.

I also want to know what the JVM have done behind the screen when i press a ctrl+c

many thanks

yslee4a at 2007-7-14 21:26:07 > top of Java-index,Java Essentials,Java Programming...