Fixes #34396
Change-Id: I35c4e3447f84e349adf7edba92ccb19b324bfe14
GitHub-Last-Rev:
4f06764109ddd9bdfbe4841fc1bebebe026eeb29
GitHub-Pull-Request: golang/go#60763
Reviewed-on: https://go-review.googlesource.com/c/go/+/502815
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
// about the underlying operating system process.
//
// On Unix systems, FindProcess always succeeds and returns a Process
-// for the given pid, regardless of whether the process exists.
+// for the given pid, regardless of whether the process exists. To test whether
+// the process actually exists, see whether p.Signal(syscall.Signal(0)) reports
+// an error.
func FindProcess(pid int) (*Process, error) {
return findProcess(pid)
}
import (
"internal/testenv"
. "os"
+ "syscall"
"testing"
)
t.Errorf("got %v want %v", got, ErrProcessDone)
}
}
+
+func TestUNIXProcessAlive(t *testing.T) {
+ testenv.MustHaveGoBuild(t)
+ t.Parallel()
+
+ p, err := StartProcess(testenv.GoToolPath(t), []string{"sleep", "1"}, &ProcAttr{})
+ if err != nil {
+ t.Skipf("starting test process: %v", err)
+ }
+ defer p.Kill()
+
+ proc, _ := FindProcess(p.Pid)
+ err = proc.Signal(syscall.Signal(0))
+ if err != nil {
+ t.Errorf("OS reported error for running process: %v", err)
+ }
+}