Description
Summary
Generally speaking, when a Go process receives a signal it will either be handled (by the runtime or by application code), ignored, or will terminate the process. There are several scenarios where it is useful to know which one will happen, and also what the original behavior was for the process (e.g. what signal.Reset(sig)
will change it to).
On unix systems, the current disposition can be obtained by runtime.getsig
and the original disposition is in runtime.fwdSig
. Neither of these are exposed to the application.
Example use case
Determining whether SIGHUP is ignored (which will be the case if run through nohup
) before registering a handler. The go runtime already does this, but there isn't a great way for application code to do it.
Proposed API
Exposing the function pointers returned by getsig
would be a bad idea. Instead, the proposal is to add to the os/signal
package a type
type Status int
const (
Default = Disposition(iota)
Ignored
Notify
Panic
Terminate
)
and methods
func CurrentStatus(sig os.Signal) Status {
// on unix, this information can be found by a combination of runtime.getsig,
// runtime.handlingSig, and runtime.sigtable
}
func StartingStatus(sig os.Signal) Status {
// on unix, this information can be found by a combination of runtime.fwdSig
// and runtime. sigtable
}