title: create detached child process in java
body: <p>I'm trying to update a running java program and for that I'm executing a shell script to do the update .
  this how a do lunch the script : </p>
  
  <pre><code>Runtime.getRuntime().exec("chmod +x " + spherDir + "/deploy.sh");
  </code></pre>
  
  <p>the problem is that inside the deploy.sh there is a command that kill the running instance before the script finished his execution.</p>
  
  <p>My question is how to create a detached process that continue his execution even when the main programe (parent programm) stops !!</p>
  
  <p>I'm on linux and I already tried <code>ProcessBuilder</code> without success.</p>
  
  <p>here the java code :</p>
  
  <pre><code>File file = new File(spherDir +"/restore.sh");
  boolean bool = file.createNewFile();
  FileWriter writer = new FileWriter(file);
  
  try
  {
      writer.write("#!/bin/sh\n\n");
      writer.write("service spher stop \n"); // stop the server chameleon
      writer.write("rm -rf " + appServerDir + " \n");
      writer.write("cp -Rap " + spherDir + "/currentdistrib/app-server  " + spherDir +"/app-server \n");
      writer.write("rm -rf " + spherDir + "/ui-server \n");
      writer.write("cp -Rap " + spherDir + "/currentdistrib/ui-server  " + spherDir + "/ui-server \n");
      writer.write("rm -rf " + spherDir + "/currentdistrib \n");
      writer.write("chmod +x " + spherDir + "/app-server/chameleon.sh \n"); /// Alaways do that to ensure that the script is runnable
      writer.write("sleep 5s \n"); /// Alaways do that to ensure that the script is runnable
      writer.write("touch README \n"); /// Alaways do that to ensure that the script is runnable
      writer.write("service spher start \n");
  
  } catch(IOException ex)
  {
      ex.printStackTrace();
  }
  finally
  {
      writer.close();
  }
  
  Runtime.getRuntime().exec("chmod 755 " + spherDir + "/restore.sh");
  ProcessBuilder pb = new ProcessBuilder("/bin/bash", spherDir + "/restore.sh");
  final Process process = pb.start();
  </code></pre>