4
0

executor_unix.go 967 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //go:build !windows
  2. // +build !windows
  3. package executor
  4. import (
  5. "context"
  6. "os/exec"
  7. "syscall"
  8. )
  9. func (e *Executor) Kill(execReq *InternalLogEntry) error {
  10. // A negative PID means to kill the whole process group. This is *nix specific behavior.
  11. return syscall.Kill(-execReq.Process.Pid, syscall.SIGKILL)
  12. }
  13. func wrapCommandInShell(ctx context.Context, finalParsedCommand string) *exec.Cmd {
  14. cmd := exec.CommandContext(ctx, "sh", "-c", finalParsedCommand)
  15. // This is to ensure that the process group is killed when the parent process is killed.
  16. cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
  17. return cmd
  18. }
  19. func wrapCommandDirect(ctx context.Context, execArgs []string) *exec.Cmd {
  20. if len(execArgs) == 0 {
  21. return nil
  22. }
  23. cmd := exec.CommandContext(ctx, execArgs[0], execArgs[1:]...)
  24. // This is to ensure that the process group is killed when the parent process is killed.
  25. cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
  26. return cmd
  27. }