3

I have a Process object, which i need to terminate at a given point in time. I tried Process.destroy(), but this does not effectively let the process to release the port it was using, due to which i cannot use it. All i need to do is to send a "Ctrl + C" to the 'Process' which already has a shutdown hook written in it, which takes care of releasing any resources.

How can i do this.

I am Using Windows

frewper
  • 1,385
  • 6
  • 18
  • 44
  • 2
    Which OS are you using ? – Brian Agnew Dec 13 '12 at 09:14
  • Shutdown hooks are not always called on abnormal program termination (depends on the underlying OS). – Neet Dec 13 '12 at 09:14
  • I am also facing the same Issue and I have explained in detail here: http://stackoverflow.com/questions/27942679/how-to-terminate-a-process-normally-created-using-processbuilder Can you please guide me that how this can be solved ? Any link ? – Bilal Ahmed Yaseen Jan 14 '15 at 13:31

2 Answers2

2

Counting on shutdown hooks for regular operation is a broken approach. You must design your application to provide its own protocol by which it can receive a shutdown signal. This is the only way to write a solid multiplatform application, where by "multiplatform" I also imply different versions of the same platform.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
  • +1 you have to write your protocol with the assumption a connection to a service could die at any point. e.g. the power might fail. You should try to give your protocol a graceful disconnect, but you cannot assume it will always be used. – Peter Lawrey Dec 13 '12 at 10:45
  • I am also facing the same Issue and I have explained in detail here: stackoverflow.com/questions/27942679/… Can you please guide me that how this can be solved ? Any link ? – Bilal Ahmed Yaseen Jan 14 '15 at 13:31
0

You can send a command using taskkill like explained in this article.

Luca Davanzo
  • 21,000
  • 15
  • 120
  • 146