nezha/cmd/agent/processgroup/process_group_windows.go

31 lines
532 B
Go
Raw Normal View History

2022-04-14 04:41:34 -04:00
//go:build windows
2021-01-28 22:59:35 -05:00
2021-08-18 05:42:26 -04:00
package processgroup
import (
2021-01-29 01:29:31 -05:00
"fmt"
2021-01-28 22:59:35 -05:00
"os/exec"
)
2021-01-29 01:29:31 -05:00
type ProcessExitGroup struct {
cmds []*exec.Cmd
}
func NewProcessExitGroup() (ProcessExitGroup, error) {
2021-01-29 01:29:31 -05:00
return ProcessExitGroup{}, nil
}
2021-01-29 01:29:31 -05:00
func (g *ProcessExitGroup) Dispose() error {
for _, c := range g.cmds {
if err := exec.Command("taskkill", "/F", "/T", "/PID", fmt.Sprint(c.Process.Pid)).Run(); err != nil {
return err
}
}
return nil
}
2021-01-29 01:29:31 -05:00
func (g *ProcessExitGroup) AddProcess(cmd *exec.Cmd) error {
g.cmds = append(g.cmds, cmd)
return nil
}