github.com/code-reading/golang@v0.0.0-20220303082512-ba5bc0e589a3/go/src/syscall/syscall_ptrace_test.go (about) 1 // Copyright 2019 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd 6 // +build darwin dragonfly freebsd linux netbsd openbsd 7 8 package syscall_test 9 10 import ( 11 "internal/testenv" 12 "os" 13 "os/exec" 14 "syscall" 15 "testing" 16 ) 17 18 func TestExecPtrace(t *testing.T) { 19 testenv.MustHaveExec(t) 20 21 bin, err := exec.LookPath("sh") 22 if err != nil { 23 t.Skipf("skipped because sh is not available") 24 } 25 26 attr := &os.ProcAttr{ 27 Sys: &syscall.SysProcAttr{ 28 Ptrace: true, 29 }, 30 } 31 proc, err := os.StartProcess(bin, []string{bin}, attr) 32 if err == nil { 33 proc.Kill() 34 } 35 if err != nil && !os.IsPermission(err) { 36 t.Fatalf("StartProcess with ptrace enabled failed: %v", err) 37 } 38 }