aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/osutil
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/osutil')
-rw-r--r--pkg/osutil/osutil.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go
index 0194a616e..7eb033652 100644
--- a/pkg/osutil/osutil.go
+++ b/pkg/osutil/osutil.go
@@ -5,6 +5,7 @@ package osutil
import (
"bytes"
+ "context"
"fmt"
"io/ioutil"
"os"
@@ -79,6 +80,14 @@ func Run(timeout time.Duration, cmd *exec.Cmd) ([]byte, error) {
return output.Bytes(), nil
}
+// CommandContext is similar to os/exec.CommandContext, but also sets PDEATHSIG to SIGKILL on linux,
+// i.e. the child will be killed immediately.
+func CommandContext(ctx context.Context, bin string, args ...string) *exec.Cmd {
+ cmd := exec.CommandContext(ctx, bin, args...)
+ setPdeathsig(cmd, true)
+ return cmd
+}
+
// Command is similar to os/exec.Command, but also sets PDEATHSIG to SIGKILL on linux,
// i.e. the child will be killed immediately.
func Command(bin string, args ...string) *exec.Cmd {