Stop process gracefully

Dear experts,

please tell me how can I stop any process gracefully. I am executing a java application from another java application. Something like

Process proc = Runtime.getRuntime().exec("java .....");

Now I need to stop the inner process. How can I do this? If I use Process.destroy() then the shutdown hook thread of the inner process is not executed. But that is important for the inner process. So not possible to use destroy() method. Please tell me how can I stop the inner process gracefully.

[551 byte] By [faisal_leada] at [2007-10-2 3:29:23]
# 1

Some more things to say. The inner java class I am calling is not mine. I have not the source file. So I cant make any change to that java class. If I execute that java class from command line and press Ctrl-C then the shutdown hook thread of that java class is executed. So If I can pass Ctrl-C from my java application to inner java application then I think the shutdown hook thread of the inner java application will be executed. But how can I do so?

faisal_leada at 2007-7-15 22:39:09 > top of Java-index,Java Essentials,Java Programming...
# 2
Have you tried inputing Ctrl-C char sequence to the process input stream?Just a wild gues... not sure whether it will work..[url http://www.feedfeeds.com/feedtv]Ajax Feed Reader[/url]
jessua at 2007-7-15 22:39:09 > top of Java-index,Java Essentials,Java Programming...
# 3
Yes I tried though I know it is not supposed to work. Ctrl-C is an interrupt and it is provided by OS.
faisal_leada at 2007-7-15 22:39:09 > top of Java-index,Java Essentials,Java Programming...
# 4
hello somebody help me please
faisal_leada at 2007-7-15 22:39:09 > top of Java-index,Java Essentials,Java Programming...
# 5
I can't hear from Java Experts
faisal_leada at 2007-7-15 22:39:09 > top of Java-index,Java Essentials,Java Programming...
# 6

Gracefully stopping a non-cooperating program is not possible. For graceful stopping the process has to have the ability to ignore the stop-signal for some time at least. And as long as it has that ability you can't force it to stop.

The only way to gracefully stop any process is that you tell it to stop and it does so. Unless it's programmed to respond to such a signal there is no way to "force it to gracefully stop".

JoachimSauera at 2007-7-15 22:39:09 > top of Java-index,Java Essentials,Java Programming...
# 7
I think there is some good solution. Any more replies please?
faisal_leada at 2007-7-15 22:39:09 > top of Java-index,Java Essentials,Java Programming...
# 8

What makes you think so? If you've got some information that says you can do so, please share it with us. What do you think that you can achieve by just saying "but tell me!"? You didn't get a solution (probably because there is no solution) and didn't provide any more information, so the answer doesn't change.

You might want to look up how to [url=http://www.catb.org/~esr/faqs/smart-questions.html]ask questions the smart way[/url].

JoachimSauera at 2007-7-15 22:39:09 > top of Java-index,Java Essentials,Java Programming...