SIGPIPE
From Wikipedia, the free encyclopedia
|
|||||
SA_SIGINFO macros
|
|||||
---|---|---|---|---|---|
None
|
On POSIX-compliant platforms, SIGPIPE is the signal thrown when a computer program attempts to write to a pipe without a process connected to the other end. The symbolic constant for SIGPIPE is defined in the header file signal.h
. Symbolic signal names are used because signal numbers can vary across platforms.
[edit] Etymology
SIG is a common prefix for signal names. PIPE refers to the Unix pipe.
[edit] Description
Unix supports the principle of piping, which allows processes to send data to other processes without the need for creating temporary files. When a pipe is broken, the process writing to it is sent the SIGPIPE signal. The default reaction to this signal for a process is to terminate.
A simple example of piping is the following.
ps l | grep make
This command, when run on a Unix-like machine (including Linux), returns a list of all processes with 'make' in their name.
- ps l returns a list of all processes (including those of other users).
- grep make selects all lines that contain the word 'make'.
If, for whatever reason, grep cannot start, the pipe is considered to be broken. SIGPIPE is sent to ps, which will terminate: It is no use writing data that no one will use. It is also possible that the reading process terminates while reading the data. This will also cause SIGPIPE to be sent to the writing process.
One can ignore SIGPIPE (using, for example, the signal system call). In this case, all system calls that would cause SIGPIPE to be sent will return -1 and set errno to EPIPE.
|