title: How do you kill a process and its children on a timeout in Go code?
body: <p>I have a situation where I need to kill a process after some time. I start the process and then:</p>
  
  <pre><code>case &lt;-time.After(timeout):
          if err := cmd.Process.Kill(); err != nil {
              return 0, fmt.Errorf("Failed to kill process: %v", err)
          }
  </code></pre>
  
  <p>kills the process. But it only kills the parent process not the 5-10 child processes that main process starts. I also tried creating a process group and then doing:</p>
  
  <pre><code>syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
  </code></pre>
  
  <p>to kill main and grandchild processes, but not working. Is there any other way I can kill the processes.</p>