You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What does 'go version' print?
go version go1.2.1 darwin/amd64
What steps reproduce the problem?
Here's a complete program that exhibits the problem (because it involves exec, it
doesn't manifest in the playground):
package main
import (
"fmt"
"os/exec"
"syscall"
)
func main() {
cmd := exec.Command("sleep", "1000000")
cmd.Start()
done := make(chan struct{})
go func() {
err := cmd.Wait()
exitStatus := cmd.ProcessState.Sys().(syscall.WaitStatus).ExitStatus()
fmt.Println("Error:", err)
fmt.Println("Status:", exitStatus)
close(done)
}()
cmd.Process.Kill()
<-done
}
What happened?
The output is
Error: signal: killed
Status: -1
What should have happened instead?
Instead, I (believe) I should have seen:
Error: signal: killed
Status: 137
Please provide any additional information below.
Looking at ExitStatus here
(http://golang.org/src/pkg/syscall/syscall_linux.go?s=4510:4546#L180) I see that -1
implies the process has not exited. But it actually has (I checked with `ps`)!
Is this a bug, or desired behavior? When I run `sleep 1000000` in a shell and then send
said process the KILL signal I get an exit code of 137 which is consistent with
http://www.tldp.org/LDP/abs/html/exitcodes.html
The text was updated successfully, but these errors were encountered:
You have to checked Signaled to see whether the process exited because of a signal.
This is a direct reflection of the way that Unix wait status work in Go.
package main
import (
"fmt"
"os/exec"
"syscall"
)
func main() {
cmd := exec.Command("sleep", "1000000")
cmd.Start()
done := make(chan struct{})
go func() {
err := cmd.Wait()
status := cmd.ProcessState.Sys().(syscall.WaitStatus)
exitStatus := status.ExitStatus()
signaled := status.Signaled()
signal := status.Signal()
fmt.Println("Error:", err)
if signaled {
fmt.Println("Signal:", signal)
} else {
fmt.Println("Status:", exitStatus)
}
close(done)
}()
cmd.Process.Kill()
<-done
}
by onsijoe:
The text was updated successfully, but these errors were encountered: