FAQ

On Tuesday, July 29, 2014 8:32:23 AM UTC-4, bernhar...@gmail.com wrote:
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
The answer depends on the OS.

For Linux, this seems to cover the bases:
http://unix.stackexchange.com/questions/14815/process-descendants
For Windows, look into Job Object
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684161(v=vs.85).aspx

--
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

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 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