Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Process.destroy() -- process carries on running?

Thread Tools

Process.destroy() -- process carries on running?

John English
Posts: n/a
Still having trouble with Process.exec(). The story so far:
- I create a separate thread to run a process and do a join(10000)
to wait for it with a timeout of 10 seconds. If the thread is
still alive after the join, interrupt it.
- The thread running the process uses exec() to create the external
process, creates two threads to read from stdout and stderr until
they get a null (indicating the process has ended), and then waits
usinf proc.waitFor(). If interrupted, it calls proc.destroy().

I display some debugging messages, and I have written a little test
program that I spawn using exec() and which counts from 1 to 60 once
a second, writing each value to a file as it does so.

What I see is:
- after 10 seconds, a message saying "Process destroyed!" from the
line after the call to proc.destroy()
- the rest of the system carries on as normal, assuming that the
process has been destroyed
- the process continues writing output to the file for the full 60

I'm using Java 1.5. This happens on both Windows and Linux, BTW.

Here is some more detailed code FWIW:

CommandThread c = new CommandThread(cmd,dir);
try {
catch (InterruptedException e) { ... }
if (c.isAlive) {


class CommandThread extends Thread {
private String command;
private File directory;
public CommandThread (String cmd, File dir) {
command = cmd;
directory = dir;
public void run() {
Process proc = null;
ReaderThread stdout = null;
ReaderThread stderr = null;
try {
proc = Runtime.getRuntime().exec(command,null,directory);
stdout = new ReaderThread(proc.getInputStream());
stderr = new ReaderThread(proc.getErrorStream());
exit = proc.waitFor();
catch (InterruptedExecption e) {
if (proc != null) {
System.out.println("Process destroyed!");


class ReaderThread extends Thread {
private BufferedReader reader;
public ReaderThread (InputStream str) {
reader = new BufferedReader(new InputStreamReader(str));
public void run() {
try {
String line;
while ((line = reader.readLine()) != null) {
catch (IOException e) { ... }

John English | (E-Mail Removed)
Senior Lecturer |
School of Computing & MIS | ** NON-PROFIT CD FOR CS STUDENTS **
University of Brighton | -- see
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[META] News server that carries comp.lang.c Tomás Ó hÉilidhe C Programming 12 01-17-2009 12:04 AM now carries all the major brands of SSL certificates jenny General Computer Support 0 11-30-2006 09:18 AM
IE patch carries security bug Au79 Computer Support 0 08-23-2006 10:40 PM
DVD Verdict reviews: SAMURAI CHAMPLOO: VOLUME 3, NEW FIST OF THE NORTH STAR: WHEN A MAN CARRIES SORROW (VOLUME 3), and more! DVD Verdict DVD Video 2 08-04-2005 07:32 AM
which country carries the best prices on digital cameras? Apkesh Digital Photography 4 03-06-2004 11:03 PM