diff options
| author | Kir Kolyshkin <kolyshkin@gmail.com> | 2023-11-16 01:42:39 -0800 |
|---|---|---|
| committer | Michael Pratt <mpratt@google.com> | 2024-02-21 21:27:03 +0000 |
| commit | cdf3249d74c4187bc0c1737e1bb6ab1aa52c0b6f (patch) | |
| tree | 1d1d02c2e659731e51349dadc12eace835631c43 /src/os/exec_unix.go | |
| parent | ccb6077d11e9e70cb17d3eaadaee4e673ee650c2 (diff) | |
| download | go-cdf3249d74c4187bc0c1737e1bb6ab1aa52c0b6f.tar.xz | |
os: make FindProcess use pidfd on Linux
Amend FindProcess to use pidfdFind, and make it return ErrProcessDone
if pidfdFind is used and the process is not found.
Since this is a change in API, introduce GODEBUG osfinderr=0 setting
to disable the feature.
Change-Id: I724c6f622f0c99f21a70b864cf7cf2b8836869ee
Reviewed-on: https://go-review.googlesource.com/c/go/+/542699
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'src/os/exec_unix.go')
| -rw-r--r-- | src/os/exec_unix.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/os/exec_unix.go b/src/os/exec_unix.go index 2c66a8be20..21d03da48e 100644 --- a/src/os/exec_unix.go +++ b/src/os/exec_unix.go @@ -106,8 +106,14 @@ func (p *Process) release() error { } func findProcess(pid int) (p *Process, err error) { - // NOOP for unix. - return newProcess(pid, unsetHandle), nil + h, err := pidfdFind(pid) + if err == ErrProcessDone { + return nil, err + } + // Ignore all other errors from pidfdFind, + // as the callers do not expect them, and + // we can use pid anyway. + return newProcess(pid, h), nil } func (p *ProcessState) userTime() time.Duration { |
