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
package main
import (
"fmt""os""os/signal"
)
funcmain() {
// Set up channel on which to send signal notifications.// We must use a buffered channel or risk missing the signal// if we're not ready to receive when the signal is sent.c:=make(chan os.Signal, 1)
// Passing no signals to Notify means that// all signals will be sent to the channel.signal.Notify(c)
// Block until any signal is received.s:=<-cfmt.Println("Got signal:", s)
}
I ran the program using go run ./main.go. As expected it'll wait for any signal, print the first signal and then exit. No surprises here.
Then I tried to interrupt the program using the kill command:
This has no effect. If I send the kill signal, then the child process is orphaned:
Interrupting the program using CTRL^C works as normal.
What did you expect to see?
Interrupting go run should propagate the signal to the child process.
What did you see instead?
go run ignores external(?) signals.
The text was updated successfully, but these errors were encountered:
I would not normally expect a program to propagate signals it receives to its children. The reason that the SIGINT triggered by Ctrl-C is sent to the child program in your case is because that signal is sent to the "process running in the foreground, attached to the terminal", which would not be go run, but the program started by go run.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I used the following example from os/signal:
I ran the program using
go run ./main.go
. As expected it'll wait for any signal, print the first signal and then exit. No surprises here.Then I tried to interrupt the program using the


kill
command:This has no effect. If I send the kill signal, then the child process is orphaned:
Interrupting the program using
CTRL^C
works as normal.What did you expect to see?
Interrupting
go run
should propagate the signal to the child process.What did you see instead?
go run
ignores external(?) signals.The text was updated successfully, but these errors were encountered: