2021-01-28 22:59:35 -05:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ProcessExitGroup struct {
|
|
|
|
cmds []*exec.Cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewProcessExitGroup() (ProcessExitGroup, error) {
|
|
|
|
return ProcessExitGroup{}, nil
|
|
|
|
}
|
|
|
|
|
2021-01-29 01:29:31 -05:00
|
|
|
func (g *ProcessExitGroup) Dispose() error {
|
2021-01-28 22:59:35 -05:00
|
|
|
for _, c := range g.cmds {
|
|
|
|
if err := syscall.Kill(-c.Process.Pid, syscall.SIGKILL); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *ProcessExitGroup) AddProcess(cmd *exec.Cmd) error {
|
|
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
|
|
|
g.cmds = append(g.cmds, cmd)
|
|
|
|
return nil
|
|
|
|
}
|