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: Unable to catch SIGHUP signal multiple times #11700

Closed
ghost opened this issue Jul 14, 2015 · 5 comments
Closed

os/signal: Unable to catch SIGHUP signal multiple times #11700

ghost opened this issue Jul 14, 2015 · 5 comments
Milestone

Comments

@ghost
Copy link

ghost commented Jul 14, 2015

I have the following code:

func HandleSIGHUP() chan os.Signal {
    sig := make(chan os.Signal, 1)

    signal.Notify(sig, syscall.SIGHUP)

    return sig
}

I "register" the signal like so:

go func() {
    for {
        <-HandleSIGHUP()

        // do something
    }
}()

The problem that I'm experiencing is that I'm only able to catch one SIGHUP. For example if I send multiple kill -SIGHUP <pid> to the process, the "register" code only runs once. How can I get it to run every time the signal is sent?

$ go version
go version go1.4.2 linux/amd64

I also posted this here: http://stackoverflow.com/questions/31395761/handle-signal-multiple-times-in-golang

@ghost ghost changed the title Handle signal multiple times in golang Unable to catch signal multiple times Jul 14, 2015
@ghost ghost changed the title Unable to catch signal multiple times Unable to catch SIGHUP signal multiple times Jul 14, 2015
@ianlancetaylor
Copy link
Contributor

It's sort of peculiar that each time through the loop you are creating and registering a new channel. Is that really what you want to do? Why not create just one channel, before the loop?

@ghost
Copy link
Author

ghost commented Jul 14, 2015

@ianlancetaylor I tried many ways but they all have the same result; the code above is my last latest try.

@ianlancetaylor
Copy link
Contributor

I can't recreate the problem.

I ran this: http://play.golang.org/p/7FAc7wzuhK . In a separate terminal window, I typed "kill -SIGHUP PID". Each time I ran that command, the program printed SIGHUP.

Please show us a complete program.

@ianlancetaylor ianlancetaylor changed the title Unable to catch SIGHUP signal multiple times os/signal: Unable to catch SIGHUP signal multiple times Jul 14, 2015
@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Jul 14, 2015
@ghost
Copy link
Author

ghost commented Jul 14, 2015

@ianlancetaylor
Indeed; unable to reproduce. I must have something else going on here.

@ghost
Copy link
Author

ghost commented Jul 14, 2015

It's working now. I probably tried to compile and didn't pay attention if the binary got updated (prob had syntax error somewhere with autobuild).

@golang golang locked and limited conversation to collaborators Jul 13, 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

2 participants