@@ -42,17 +42,18 @@ causes the program to exit with a stack dump. A SIGTSTP, SIGTTIN, or
42
42
SIGTTOU signal gets the system default behavior (these signals are
43
43
used by the shell for job control). The SIGPROF signal is handled
44
44
directly by the Go runtime to implement runtime.CPUProfile. Other
45
- signals are ignored .
45
+ signals will be caught but no action will be taken .
46
46
47
- If the Go program is started with either SIGHUP or SIGINT ignored,
48
- they will remain ignored. Go always registers a handler for the other
49
- signals.
47
+ If the Go program is started with either SIGHUP or SIGINT ignored
48
+ (signal handler set to SIG_IGN), they will remain ignored.
50
49
51
50
If the Go program is started with a non-empty signal mask, that will
52
51
generally be honored. However, some signals are explicitly unblocked:
53
52
the synchronous signals, SIGILL, SIGTRAP, SIGSTKFLT, SIGCHLD, SIGPROF,
54
53
and, on GNU/Linux, signals 32 (SIGCANCEL) and 33 (SIGSETXID)
55
- (SIGCANCEL and SIGSETXID are used internally by glibc).
54
+ (SIGCANCEL and SIGSETXID are used internally by glibc). Subprocesses
55
+ started by os.Exec, or by the os/exec package, will inherit the
56
+ modified signal mask.
56
57
57
58
Changing the behavior of signals in Go programs
58
59
@@ -65,12 +66,12 @@ channels. Specifically, it applies to the signals SIGHUP, SIGINT,
65
66
SIGQUIT, SIGABRT, and SIGTERM. It also applies to the job control
66
67
signals SIGTSTP, SIGTTIN, and SIGTTOU, in which case the system
67
68
default behavior does not occur. It also applies to some signals that
68
- are otherwise ignored : SIGUSR1, SIGUSR2, SIGPIPE, SIGALRM, SIGCHLD ,
69
- SIGURG, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGWINCH, SIGIO, SIGPWR, SIGSYS ,
70
- SIGINFO, SIGTHR, SIGWAITING, SIGLWP, SIGFREEZE, SIGTHAW, SIGLOST ,
71
- SIGXRES, SIGJVM1, SIGJVM2, and any real time signals used on the
72
- system. Note that not all of these signals are available on all
73
- systems.
69
+ otherwise cause no action : SIGUSR1, SIGUSR2, SIGPIPE, SIGALRM,
70
+ SIGCHLD, SIGCONT, SIGURG, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGWINCH,
71
+ SIGIO, SIGPWR, SIGSYS, SIGINFO, SIGTHR, SIGWAITING, SIGLWP, SIGFREEZE,
72
+ SIGTHAW, SIGLOST, SIGXRES, SIGJVM1, SIGJVM2, and any real time signals
73
+ used on the system. Note that not all of these signals are available
74
+ on all systems.
74
75
75
76
If the program was started with SIGHUP or SIGINT ignored, and Notify
76
77
is called for either signal, a signal handler will be installed for
@@ -89,15 +90,24 @@ Notify for that signal, the signal will once again be blocked.
89
90
90
91
SIGPIPE
91
92
92
- When a Go program receives an EPIPE error from the kernel while
93
- writing to file descriptors 1 or 2 (standard output or standard
94
- error), it will raise a SIGPIPE signal. If the program is not
95
- currently receiving SIGPIPE via a call to Notify, this will cause the
96
- program to exit with SIGPIPE. On descriptors other than 1 or 2, the
97
- write will return the EPIPE error. This means that, by default,
98
- command line programs will behave like typical Unix command line
99
- programs, while other programs will not crash with SIGPIPE when
100
- writing to a closed network connection.
93
+ When a Go program writes to a broken pipe, the kernel will raise a
94
+ SIGPIPE signal.
95
+
96
+ If the program has not called Notify to receive SIGPIPE signals, then
97
+ the behavior depends on the file descriptor number. A write to a
98
+ broken pipe on file descriptors 1 or 2 (standard output or standard
99
+ error) will cause the program to exit with a SIGPIPE signal. A write
100
+ to a broken pipe on some other file descriptor will take no action on
101
+ the SIGPIPE signal, and the write will fail with an EPIPE error.
102
+
103
+ If the program has called Notify to receive SIGPIPE signals, the file
104
+ descriptor number does not matter. The SIGPIPE signal will be
105
+ delivered to the Notify channel, and the write will fail with an EPIPE
106
+ error.
107
+
108
+ This means that, by default, command line programs will behave like
109
+ typical Unix command line programs, while other programs will not
110
+ crash with SIGPIPE when writing to a closed network connection.
101
111
102
112
Go programs that use cgo or SWIG
103
113
0 commit comments