Audit of 9af1463
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package procgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
type Cmd struct {
|
||||
*exec.Cmd
|
||||
}
|
||||
|
||||
func Command(name string, args ...string) *Cmd {
|
||||
return group(exec.Command(name, args...))
|
||||
}
|
||||
|
||||
func CommandContext(ctx context.Context, name string, args ...string) *Cmd {
|
||||
cmd := group(exec.CommandContext(ctx, name, args...))
|
||||
cmd.Cancel = cmd.Kill
|
||||
return cmd
|
||||
}
|
||||
|
||||
func group(cmd *exec.Cmd) *Cmd {
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
return &Cmd{Cmd: cmd}
|
||||
}
|
||||
|
||||
func (cmd *Cmd) Kill() error {
|
||||
return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
|
||||
}
|
||||
Reference in New Issue
Block a user