package signal
import "os/signal"
Package signal implements access to incoming signals.
Index ¶
Examples ¶
Functions ¶
func Notify ¶
Notify causes package signal to relay incoming signals to c. If no signals are listed, all incoming signals will be relayed to c. Otherwise, just the listed signals will.
Package signal will not block sending to c: the caller must ensure that c has sufficient buffer space to keep up with the expected signal rate. For a channel used for notification of just one signal value, a buffer of size 1 is sufficient.
It is allowed to call Notify multiple times with the same channel: each call expands the set of signals sent to that channel. The only way to remove signals from the set is to call Stop.
It is allowed to call Notify multiple times with different channels
and the same signals: each channel receives copies of incoming
signals independently.
Code:play
Example¶
package main
import (
"fmt"
"os"
"os/signal"
)
func main() {
// 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)
signal.Notify(c, os.Interrupt, os.Kill)
// Block until a signal is received.
s := <-c
fmt.Println("Got signal:", s)
}
func Stop ¶
Stop causes package signal to stop relaying incoming signals to c. It undoes the effect of all prior calls to Notify using c. When Stop returns, it is guaranteed that c will receive no more signals.
Bugs ¶
☞ This package is not yet implemented on Plan 9.
Source Files ¶
- Version
- v1.4.0-rc.2
- Published
- Dec 2, 2014
- Platform
- windows/amd64
- Imports
- 3 packages
- Last checked
- 3 minutes ago –
Tools for package owners.