FAQ
Hi all,

I already asked on StackOverflow
<http://stackoverflow.com/questions/24982845/process-kill-on-child-processes>,
but couldn't find a solution yet.

I'm trying to stop the process started with exec.Command("go", "run",
"server.go") and all its child processes.
But when I call cmd.Process.Kill() and the go process stops, the child
process (a web server in server.go) continues to run.

package main

import (
"fmt"
"os/exec"
"time"
)

func run() *exec.Cmd {
cmd := exec.Command("go", "run", "server.go")
cmd.Start()
return cmd
}

func main() {
cmd := run()
time.Sleep(time.Second * 2)
cmd.Process.Kill()
cmd.Process.Wait()
  // Child process (server.go) is still running!

fmt.Scanln()
}

It looks like Process.Kill() only stops the go (run) process, but leaves
its child process (web server) running.

^C kills the whole process group, including all child (and sub-child)
processes. How can I do the same?

I tried cmd.Process.Signal(os.Interrupt), syscall.SIGINT, syscall.SIGQUIT
and syscall.SIGKILL, none of which killed all the processes.

Thanks,
Bernhard

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 8 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 29, '14 at 1:44p
activeJul 30, '14 at 12:29p
posts8
users5
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase