title: Not able to kill processes that I started using my Go code
body: <p>I am trying to write a go package that can run a bunch of process and stop/restart them. It is the stop/restart part that is causing the problem for some kind of applications.</p>
  
  <p>I use the <a href="https://godoc.org/os/exec" rel="nofollow noreferrer">https://godoc.org/os/exec</a> library to launch processes. Let's say I launch two process firefox and another process could <code>curl blog.golang.org</code> which would keep running.</p>
  
  <p>This is how I launch processes and how I stop them</p>
  
  <pre><code>func newWorker(proc *Process) *worker {
      cmd := exec.Command(proc.Executable, proc.Args...)
      cmd.Env = proc.Env
      return &amp;worker{
          status:  "ready",
          command: cmd,
      }
  }
  
  func (w *worker) start(crashed chan *worker, completed chan struct{}) {
      w.status = "running"
      err := w.command.Start()
      if err != nil {
          fmt.Println(err)
          // signal a crash
          w.status = "crashed"
          crashed &lt;- w
          return
      }
      fmt.Println("ran ", w.command.Path, w.command.Process.Pid)
      completed &lt;- struct{}{}
  }
  
  func (w *worker) stop(crashed chan *worker, completed chan struct{}) {
      w.status = "stopped"
      err := w.command.Process.Kill()
      if err != nil {
          fmt.Println("couldn't kill process ", w.command.Path)
      }
      completed &lt;- struct{}{}
  }
  </code></pre>
  
  <p>When I run my application to start these process, it launches both the curl command and firefox, but when I try to call the stop method it is kills the processes without any errors but I still see the firefox window open, so I am not sure if the process has exited or not. I tried killing the processes with both <code>Kill</code> and <code>Signal(os.Kill)</code> both had the same result.</p>
  
  <p>I also tried to change the way I was creating the processes by using <code>Run</code> instead of <code>Start</code> but in that case while calling the stop method I got these errors</p>
  
  <pre><code>os: process already finished  couldn't kill process  /usr/bin/curl
  exit status 0  KILLING  /usr/bin/curl
  os: process already finished  couldn't kill process  /usr/bin/firefox
  </code></pre>
  
  <p>and the firefox window was still open, I also tried to print out the <code>ProcessState</code> field for each command that I was running but it turned out to be <code>nil</code></p>
  
  <p>I am not sure what to do, I want to make sure that my code 100% kills these processes</p>