<p>I launch a child process in Java as follows:</p>

<pre><code>final String[] cmd = {"&lt;childProcessName&gt;"};
Process process = Runtime.getRuntime().exec(cmd);
</code></pre>

<p>It now runs in the background. All good and fine. </p>

<p>If my program now crashes (it <em>is</em> still in dev :-)) the child process still seems to hang around. How can I make it automatically end when the parent Java process dies?</p>

<p>If it helps, I'm using Mac OS X 10.5</p>

I worked it out myself already. I add a shutdown hook, as follows:
```
```
final String[] cmd = {"<childProcessName>"};
final Process process = Runtime.getRuntime().exec(cmd);
Runnable runnable = new Runnable() {
    public void run() {
        process.destroy();
    }
};
Runtime.getRuntime().addShutdownHook(new Thread(runnable));
```
```