title: How to create a detached process in java on linux
body: <p>I am currently writing a java program that needs to run the linux <code>rpm</code> command and part of the <code>rpm</code> install stops the jvm that the <code>rpm</code> command was launched from.</p>
  
  <p>I have tried to run process builder with the <code>nohup</code> and <code>&amp;</code> then as well to detach the process to no avail as well as try <code>Runtime.exec()</code> with no success also using <code>nohup</code> and <code>&amp;</code> the code I have done to launch the process is posted below. </p>
  
  <p>They always exit and give an error saying the process that was doing the update has exited so the <code>rpm</code> command has failed.</p>
  
  <p>Why are these calls to spawn a detached process failing and exiting when the jvm exits?</p>
  
  <pre><code>public static void noWaitrunProcess(String commands[], String commandInputText) 
          throws InterruptedException {
      ProcessInfo processInfo = new ProcessInfo();
      BufferedWriter writer = null;
      OutputStream outputStream = null;
      try {
          ProcessBuilder builder = new ProcessBuilder(commands);
          builder.redirectErrorStream(true);
          Process process = builder.start();
          if(commandInputText != null){
              outputStream = process.getOutputStream();
              writer = new BufferedWriter(new OutputStreamWriter(outputStream));
              writer.write(commandInputText);
              writer.close();
          }
      } catch (IOException e) {
          processInfo.procOutput = "error running process";
      } finally {
          if(writer != null)
          {
              try {
                  writer.close();
              } catch (IOException e) {
              }
          }
      }
  }
  </code></pre>
  
  <p>I am currently getting this error when the install is attemped</p>
  
  <pre><code>D:   install: waitpid(5668) rc 5668 status f secs 0.099
  error: %pre(a[[-3.0-9.160513095338.i686) scriptlet failed, signal 15
  error:   install: %pre scriptlet failed (2), skipping app-3.0-9.160513095338
  </code></pre>