Skip to content

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

@wolf0403

Description

@wolf0403

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions