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

os/signal: code example for Notify tries to catch os.Kill which doesn't work #13080

Closed
wolf0403 opened this issue Oct 28, 2015 · 3 comments
Closed

Comments

@wolf0403
Copy link

In the code example for os/signal/#Notify,

signal.Notify(c, os.Interrupt, os.Kill)

tries to catch os.Kill signal, which doesn't work on Linux platforms.

Steps to reproduce:
Code is taken from the doc.

$ cat kill.go
package main

import (
        "fmt"
        "os"
        "os/signal"
)

func main() {
        c := make(chan os.Signal, 1)
        signal.Notify(c, os.Interrupt, os.Kill)
        s := <-c
        fmt.Println("Got signal ", s)
}

$ go build kill.go
$ ./kill &
[1] 10300
$ kill -KILL $!
$
[1]+  Killed                  ./kill

Ctrl-C / -s SIGINT works fine but SIGKILL is not caught.

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Oct 28, 2015
@rakyll rakyll changed the title code example in os/signal/#Notify tries to catch os.Kill which doesn't work. os/signal: code example for Notify tries to catch os.Kill which doesn't work Oct 28, 2015
@vapao
Copy link

vapao commented Oct 28, 2015

SIGKILL 9 Kill(can't be caught or ignored) (POSIX), the SIGKILL like can't be caught.

@davecheney
Copy link
Contributor

@wolf0403 @Yooke would either of you like to send a pull request to fix the example?

https://golang.org/doc/contribute.html

@gopherbot
Copy link

CL https://golang.org/cl/16467 mentions this issue.

@rakyll rakyll closed this as completed in 3356624 Oct 29, 2015
@golang golang locked and limited conversation to collaborators Nov 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants