github.com/sl1pm4t/consul@v1.4.5-0.20190325224627-74c31c540f9c/agent/exec/exec_unix.go (about) 1 // +build !windows 2 3 package exec 4 5 import ( 6 "os" 7 "os/exec" 8 "syscall" 9 ) 10 11 // Script returns a command to execute a script through a shell. 12 func Script(script string) (*exec.Cmd, error) { 13 shell := "/bin/sh" 14 if other := os.Getenv("SHELL"); other != "" { 15 shell = other 16 } 17 return exec.Command(shell, "-c", script), nil 18 } 19 20 func SetSysProcAttr(cmd *exec.Cmd) { 21 cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} 22 } 23 24 // KillCommandSubtree kills the command process and any child processes 25 func KillCommandSubtree(cmd *exec.Cmd) error { 26 return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) 27 }