Skip to content

Commit

Permalink
kill cmd support windows
Browse files Browse the repository at this point in the history
  • Loading branch information
UlricQin committed May 31, 2022
1 parent 9381bfa commit e635f21
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/agentd/timer/cmd_nix.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ func CmdStart(cmd *exec.Cmd) error {
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
return cmd.Start()
}

func CmdKill(cmd *exec.Cmd) error {
return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
}
4 changes: 4 additions & 0 deletions src/agentd/timer/cmd_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ package timer
func CmdStart(cmd *exec.Cmd) error {
return cmd.Start()
}

func CmdKill(cmd *exec.Cmd) error {
return cmd.Process.Kill()
}
3 changes: 1 addition & 2 deletions src/agentd/timer/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path"
"strings"
"sync"
"syscall"

"github.com/toolkits/pkg/file"
"github.com/toolkits/pkg/runner"
Expand Down Expand Up @@ -298,7 +297,7 @@ func killProcess(t *Task) {

log.Printf("D: begin kill process of task[%d]", t.Id)

err := syscall.Kill(-t.Cmd.Process.Pid, syscall.SIGKILL)
err := CmdKill(t.Cmd)
if err != nil {
t.SetStatus("killfailed")
log.Printf("D: kill process of task[%d] fail: %v", t.Id, err)
Expand Down

0 comments on commit e635f21

Please sign in to comment.