File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Linux / UNIX and the fly likes Equivalent kill -n for process.destroy() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Equivalent kill -n for process.destroy()" Watch "Equivalent kill -n for process.destroy()" New topic

Equivalent kill -n for process.destroy()

E Hill

Joined: Aug 11, 2009
Posts: 7

I am trying to emulate the functionality of a currently existing Java application, here applications and .jars run by creating a process and they are shutdown by process.destroy().

My problem is that the process that will be doing the killing will be run from the command line, or a separate java program, so the only method of killing the process is to find the PID from ps and then use the linux kill command to kill the processes. So what is the equivalent flag in kill to the process.destroy()?

E. Hill
Peter Johnson

Joined: May 14, 2008
Posts: 5852

E, welcome to Java Ranch!

I use -9 to make sure the process gets killed. Example to kill proccess with pid of 1234:

kill -9 1234

JBoss In Action
E Hill

Joined: Aug 11, 2009
Posts: 7

Thanks for the reply, does java use the equivalent of -9 in its process destroy? Killing everything with no chance of running and cleanup scripts etc?

We have the example of Process.destroy() in the program source code, however we are unable to kill the processes from Java as we will be launching through the command line and will not be starting processes in Java. We dont want to be too heavy-handed if possible, so would prefer to only use -9 as a last resort.

I agree. Here's the link:
subject: Equivalent kill -n for process.destroy()
It's not a secret anymore!