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
PID: <pid>
trying to kill
Success: false signal: terminated
A signal terminate to the sleep process should still kill it since execve system call should reset all signal handlers to the default ones. But for some reason this doesn't happen with ignore. To work around this I had to add empty signal handler for the terminate signal so only the parent process ignore the signal while the children still have their default handler in place.
What did you see instead?
PID: <pid>
trying to kill
trying to kill
trying to kill
Success: true exit status 0
The text was updated successfully, but these errors were encountered:
bradfitz
changed the title
signal.Ignore is inherited by children after a forkExec
os/signal: signal.Ignore is inherited by children after a forkExec
May 24, 2017
POSIX specifies that for execve signals whose handlers are either SIG_IGN or SIG_DFL are left unchanged: that is, an ignored signal is still ignored after an execve. Calling signal.Ignore sets the handler to SIG_IGN, so what are you seeing is that the execution is preserving the ignored state of the signal. Go doesn't have to follow POSIX, of course, but you are basically suggesting that os.StartProcess should override ignored signals and set them back to the default. We could do that, but is it the right thing to do?
There is a clear utility to being able to ignore signals across execve: that's how the nohup utility works. Today, we could write the nohup utility in Go. With your proposed change, we would not be able to. It's easy to catch but ignore a signal in Go: just call signal.Notify(make(chan os.Signal)). So your proposed change would make Go strictly less useful than it is today. That does not seem wise.
One possibility would be to add something to syscall.SysProcAttr that lets you specify signal dispositions (either ignored or default). Then you could easily control signals. But given that it is fairly simple to do that anyhow, I'm not sure how useful that would be.
@ianlancetaylor thanks for your reply and indeed u have a very good point. Also thanks for the hint how to work around this with signal.Notify.
Feel free to close the issue.
What version of Go are you using (
go version
)?go version go1.8.1 linux/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
When run the program should print
A signal terminate to the
sleep
process should still kill it sinceexecve
system call should reset all signal handlers to the default ones. But for some reason this doesn't happen with ignore. To work around this I had to add empty signal handler for the terminate signal so only the parent process ignore the signal while the children still have their default handler in place.What did you see instead?
The text was updated successfully, but these errors were encountered: