diff --git a/muzan.go b/muzan.go index 2ec21cc..3a2d993 100644 --- a/muzan.go +++ b/muzan.go @@ -77,7 +77,7 @@ func (oni *Oni) Start() error { } var err error cmd := exec.Command(oni.Cmd, oni.Args...) - cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} + setgpid(cmd) cmd.Env = oni.Envs cmd.Dir = oni.Dir var out io.Writer @@ -111,18 +111,6 @@ func (oni *Oni) Stop() error { return oni.cmd.Process.Signal(syscall.SIGTERM) } -func (oni *Oni) Kill() error { - if oni.cmd == nil { - return nil - } - pgid, err := syscall.Getpgid(oni.cmd.Process.Pid) - if err == nil { - return syscall.Kill(-pgid, 15) // note the minus sign - } - return oni.cmd.Process.Kill() - // return oni.cmd.Process.Kill() -} - func (oni *Oni) end(v interface{}) { if v == nil { oni.StateChange(ENDED) diff --git a/muzanctl.go b/muzanctl.go new file mode 100644 index 0000000..2cd2e1e --- /dev/null +++ b/muzanctl.go @@ -0,0 +1,24 @@ +//go:build !windows +// +build !windows + +package configui + +import ( + "os/exec" + "syscall" +) + +func setgpid(cmd *exec.Cmd) { + cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} +} + +func (oni *Oni) Kill() error { + if oni.cmd == nil { + return nil + } + pgid, err := syscall.Getpgid(oni.cmd.Process.Pid) + if err == nil { + return syscall.Kill(-pgid, 15) // note the minus sign + } + return oni.cmd.Process.Kill() +} diff --git a/muzanctrl_windows.go b/muzanctrl_windows.go new file mode 100644 index 0000000..64a8953 --- /dev/null +++ b/muzanctrl_windows.go @@ -0,0 +1,13 @@ +package configui + +import "os/exec" + +func setgpid(cmd *exec.Cmd) { +} + +func (oni *Oni) Kill() error { + if oni.cmd == nil { + return nil + } + return oni.cmd.Process.Kill() +}