Closed
Description
Go version
go version devel go1.23-5d4e8f5 Thu Feb 22 01:57:32 2024 +0000 linux/amd64
Output of go env
in your module/workspace:
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/stgraber/.cache/go-build'
GOENV='/home/stgraber/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/stgraber/data/code/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/stgraber/data/code/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/stgraber/sdk/gotip'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/stgraber/sdk/gotip/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.23-5d4e8f5 Thu Feb 22 01:57:32 2024 +0000'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-I/home/stgraber/data/code/go/deps/raft/include/ -I/home/stgraber/data/code/go/deps/cowsql/include/'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-L/home/stgraber/data/code/go/deps/raft/.libs -L/home/stgraber/data/code/go/deps/cowsql/.libs/'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3052341145=/tmp/go-build -gno-record-gcc-switches'
What did you do?
Following https://pkg.go.dev/os#FindProcess, I have logic which assumes that on Linux systems, os.FindProcess will always succeed and that the resulting record can then be used with Signal to validate its actual existence.
However it appears the recent switch to using PIDFD within Go may have regressed this?
@kolyshkin
Example code:
package main
import (
"fmt"
"os"
"syscall"
)
func main() {
// Go doc says this will always work on Linux.
pr, err := os.FindProcess(12345678)
if err != nil {
fmt.Printf("Supposedly unreachable code reached\n")
os.Exit(1)
}
// Check if process exist by sending signal 0.
err = pr.Signal(syscall.Signal(0))
if err != nil {
fmt.Printf("Process doesn't exist\n")
os.Exit(0)
}
fmt.Printf("Process exists\n")
}
What did you see happen?
stgraber@castiana:~$ go version
go version go1.21.5 linux/amd64
stgraber@castiana:~$ go run ./main.go
Process doesn't exist
stgraber@castiana:~$
What did you expect to see?
stgraber@castiana:~$ gotip version
go version devel go1.23-5d4e8f5 Thu Feb 22 01:57:32 2024 +0000 linux/amd64
stgraber@castiana:~$ gotip run ./main.go
Supposedly unreachable code reached
exit status 1
stgraber@castiana:~$