Not using pure Java.
Your simplest alternative is to use Runtime.exec()
to run a kill -9 <pid>
command as an external process.
Unfortunately, it is not that simple to get hold of the PID. You will either need to use reflection black-magic to access the private int pid
field, or mess around with the output from the ps
command.
UPDATE - actually, there is another way. Create a little utility (C program, shell script, whatever) that will run the real external application. Code the utility so that it remembers the PID of the child process, and sets up a signal handler for SIGTERM that will SIGKILL the child process.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…