group, and Chris Hines' answer cover the other parts of your question.
As far as the SO question, the answer is a good one, don't use `go run`. It
will be more predictable to build and install a package as a whole, than
try to use run on separate go source files.
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
--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.