title: Start a process in Go and detach from it
body: <p>I need to start a new process in Go with the following requirements:</p>
  
  <ul>
  <li>The starting process should run even after the Go process is terminated</li>
  <li>I need to be able to set the Unix user/group that's running it</li>
  <li>I need to be able to set the environment variables inherited</li>
  <li>I need control over std in/out/err</li>
  </ul>
  
  <p>Here is an attempt:</p>
  
  <pre><code>var attr = os.ProcAttr {
  Dir: "/bin",
  Env: os.Environ(),
  Files: []*os.File{
      os.Stdin,
      "stdout.log",
      "stderr.log",
    },
  }
  process, err := os.StartProcess("sleep", []string{"1"}, &amp;attr)
  </code></pre>
  
  <p>This works fine but has the following shortcomings from the requirements:</p>
  
  <ul>
  <li>No way to set Unix user/group</li>
  <li>The started process ends when the Go process (parent) stops</li>
  </ul>
  
  <p>This needs to run on Linux only if that simplifies things.</p>