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