title: Can't detach child process when main process is started from systemd
body: <p>I want to spawn long-running child processes that survive when the main process restarts/dies. This works fine when running from the terminal:</p>
  
  <pre><code>$ cat exectest.go
  package main
  
  import (
          "log"
          "os"
          "os/exec"
          "syscall"
          "time"
  )
  
  func main() {
          if len(os.Args) == 2 &amp;&amp; os.Args[1] == "child" {
                  for {   
                          time.Sleep(time.Second)
                  }
          } else {
                  cmd := exec.Command(os.Args[0], "child")
                  cmd.SysProcAttr = &amp;syscall.SysProcAttr{Setsid: true}
                  log.Printf("child exited: %v", cmd.Run())
          }
  }
  $ go build
  $ ./exectest
  ^Z
  [1]+  Stopped                 ./exectest
  $ bg
  [1]+ ./exectest &amp;
  $ ps -ef | grep exectest | grep -v grep | grep -v vim
  snowm     7914  5650  0 23:44 pts/7    00:00:00 ./exectest
  snowm     7916  7914  0 23:44 ?        00:00:00 ./exectest child
  $ kill -INT 7914 # kill parent process
  [1]+  Exit 2                  ./exectest
  $ ps -ef | grep exectest | grep -v grep | grep -v vim
  snowm     7916     1  0 23:44 ?        00:00:00 ./exectest child
  </code></pre>
  
  <p>Note that the child process is still alive after parent process was killed. However, if I start the main process from systemd like this...</p>
  
  <pre><code>[snowm@localhost exectest]$ cat /etc/systemd/system/exectest.service 
  [Unit]
  Description=ExecTest
  
  [Service]                        
  Type=simple
  ExecStart=/home/snowm/src/exectest/exectest
  User=snowm
  
  [Install]
  WantedBy=multi-user.target
  $ sudo systemctl enable exectest
  ln -s '/etc/systemd/system/exectest.service' '/etc/systemd/system/multi-user.target.wants/exectest.service'
  $ sudo systemctl start exectest
  </code></pre>
  
  <p>... then the child also dies when I kill the main process:</p>
  
  <pre><code>$ ps -ef | grep exectest | grep -v grep | grep -v vim
  snowm     8132     1  0 23:55 ?        00:00:00 /home/snowm/src/exectest/exectest
  snowm     8134  8132  0 23:55 ?        00:00:00 /home/snowm/src/exectest/exectest child
  $ kill -INT 8132
  $ ps -ef | grep exectest | grep -v grep | grep -v vim
  $
  </code></pre>
  
  <p>How can I make the child survive?</p>
  
  <p>Running go version go1.4.2 linux/amd64 under CentOS Linux release 7.1.1503 (Core).</p>