Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Killing a Process  RSS feed

 
Proteu Alcebidiano
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,

Is it possible to kill a process which throws a SO's exception? I'm trying here with the System.exit(-1) command, but the java program cannot kill yourself and the process launched by this java program.

E.g.

Runtime.exec(theProcess); //This is a fail process

...

System.exit(-1); //theProcess Locks the java program, and this command is not executed...

What's the pure java solution (if exists) for this problem?

Thanks,

Proteu. :roll:
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Proteu Alcebidiano:
Hello guys,

Is it possible to kill a process which throws a SO's exception? I'm trying here with the System.exit(-1) command, but the java program cannot kill yourself and the process launched by this java program.

E.g.

Runtime.exec(theProcess); //This is a fail process

...

System.exit(-1); //theProcess Locks the java program, and this command is not executed...

What's the pure java solution (if exists) for this problem?

Thanks,

Proteu. :roll:


When you to Runtime.exec you are returned a Process. If you dont handle this Process the program you executed can get stuck.



You should get the errorstream and the input stream of the process P and be sure to keep them empty, or that process will stall.

There is also p.destroy();
 
Proteu Alcebidiano
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, but if a process don't have any handles and launching an application error (for Windows Operating System, e.g.), this window locks the process until the user closes the window...it's so bad for automated systems

In this case, i think that i go to make my own Process' Launcher

Thanks for reply.

Proteu
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what you mean by handles? You have a reference to the process. The whole point in using seperate processes is because they can't bring down your main process.

And whats SO's exceptions?

I really can't understand your issue here, are you new to Java?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!