Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syscall: Kill pid argument cannot be a pgid because it is forced to be an unsigned int #53199

Closed
singuliere opened this issue Jun 2, 2022 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@singuliere
Copy link

singuliere commented Jun 2, 2022

What version of Go are you using (go version)?

$ go version
go version go1.18 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/singuliere/.cache/go-build"
GOENV="/home/singuliere/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/singuliere/.go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/singuliere/.go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2335311840=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
	"fmt"
	"os/exec"
	"syscall"
	"time"
)

func main() {
	c := exec.Command(ctx, "/bin/bash", "-c", `echo "sleep 100000" | bash`)
	c.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
	c.Start()
	fmt.Println("running err = ", c.Process.Pid)
	time.Sleep(5 * time.Second)
	syscall.Kill(-c.Process.Pid, syscall.SIGKILL)
	fmt.Println("run err = ", c.Wait())
}

What did you expect to see?

Because of the negative argument to syscall.Kill I was expecting all children of the processgroup to be killed, as per https://man7.org/linux/man-pages/man2/kill.2.html

What did you see instead?

The argument of syscall.Kill is converted into an unsigned integer instead of being passed as a negative number and only the immediate child is killed, not the entire process group. Which pretty much defeats the purpose of creating a process group in this particular case.

@singuliere singuliere changed the title affected/package: https://pkg.go.dev/syscall affected/package: https://pkg.go.dev/syscall Kill pid argument cannot be a pgid because it is forced to be an unsigned int Jun 2, 2022
@mengzhuo mengzhuo changed the title affected/package: https://pkg.go.dev/syscall Kill pid argument cannot be a pgid because it is forced to be an unsigned int syscall: Kill pid argument cannot be a pgid because it is forced to be an unsigned int Jun 2, 2022
@ianlancetaylor
Copy link
Contributor

Your program does not compile because ctx is not defined. When I remove that, the programs works as expected on my Debian linux/amd64 system. It's true that the PID value is converted from int to uintptr, but this doesn't matter; the kernel will convert it back again.

Can you show us exactly what is wrong after you run your program?

@ianlancetaylor ianlancetaylor added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 2, 2022
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Jun 2, 2022
@singuliere
Copy link
Author

@ianlancetaylor I was a little too quick when making my tests it seems... sorry for the noise. It works as advertised.

@golang golang locked and limited conversation to collaborators Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants