Contained WithinFind More DocumentationFeatured Support Resources | Download this book in PDF (892 KB)
signal(3HEAD)NAME | SYNOPSIS | DESCRIPTION | SEE ALSO | NOTES NAME
SYNOPSIS#include <signal.h> DESCRIPTION
A signal is an asynchronous notification of an event. A signal is said to be generated for (or sent to) a process when the event associated with that signal first occurs. Examples of such events include hardware faults, timer expiration and terminal activity, as well as the invocation of the kill(2) or sigsend(2) functions. In some circumstances, the same event generates signals for multiple processes. A process may request a detailed notification of the source of the signal and the reason why it was generated. See siginfo(3HEAD). Signals can be generated synchronously or asynchronously. Events directly caused by the execution of code by a thread, such as a reference to an unmapped, protected, or bad memory can generate Signals may also be generated by calling kill(), sigqueue(), or sigsend(). Events such as keyboard interrupts generate signals, such as SIGINT, which are sent to the target process. Such events are referred to as interrupts; signals generated by interrupts are said to be asynchronously generated. Asynchronously generated signals are not directed to a particular thread but are handled by an arbitrary thread that meets either of the following conditions: SIGNAL DELIVERYA signal is said to be delivered to a process when a thread or LWP within the process takes the appropriate action for the disposition of the signal. Delivery of a signal can be blocked. There are two methods for handling delivery of a signal in a multithreaded application. The first method specifies a signal handler function to execute when the signal is received by the process. See sigaction(2). The second method creates a thread to handle the receipt of the signal sigaction() can be used for both synchronously and asynchronously generated signals. sigwait() will only work for asynchronously generated signals, as synchronously generated signals are sent to the thread that caused the event. sigwait() is the recommended interface for use with a multithreaded application. See sigwait(2). SIGNAL MASKEach thread or LWP has a signal mask that defines the set of signals currently blocked from delivery to it. The signal mask of the main thread or LWP is inherited from the signal mask of the thread or LWP that created it in the parent process. The selection of the thread or LWP within the process that is to take the appropriate action for the signal is based on the method of signal generation and the signal masks of the threads or LWPs in the receiving process. Signals that are generated by action of a particular thread or LWP such as hardware faults are delivered to the thread or LWP that caused the signal. See thr_sigsetmask(3THR) or sigprocmask(2). See alarm(2) for current semantics of delivery of SIGALRM. Signals that are directed to a particular thread or LWP are delivered to the targeted thread or LWP. See thr_kill(3THR) or _lwp_kill(2). If the selected thread or LWP has blocked the signal, it remains pending on the thread or LWP until it is unblocked. For all other types of signal generation (for example, kill(2), sigsend(2), terminal activity, and other external events not ascribable to a particular thread or LWP) one of the threads or LWPs that does not have the signal blocked is selected to process the signal. If all the threads or LWPs within the process block the signal, it remains pending on the process until a thread or LWP in the process unblocks it. If the action associated with a signal is set to ignore the signal then both currently pending and subsequently generated signals of this type are discarded immediately for this process. The determination of which action is taken in response to a signal is made at the time the signal is delivered to a thread or LWP within the process, allowing for any changes since the time of generation. This determination is independent of the means by which the signal was originally generated. The signals currently defined by <signal.h> are as follows:
The symbols SIGRTMIN through SIGRTMAX are evaluated dynamically in order to permit future configurability. SIGNAL DISPOSITIONA process, using a signal(3C), sigset(3C) or sigaction(2) system call, may specify one of three dispositions for a signal: take the default action for the signal, ignore the signal, or catch the signal. Default Action: SIG_DFLA disposition of SIG_DFL specifies the default action. The default action for each signal is listed in the table above and is selected from the following: Ignore Signal: SIG_IGNA disposition of SIG_IGN specifies that the signal is to be ignored. Setting a signal action to SIG_IGN for a signal that is pending causes the pending signal to be discarded, whether or not it is blocked. Any queued values pending are also discarded, and the resources used to queue them are released and made available to queue other signals. Catch Signal: function addressA disposition that is a function address specifies that, when it gets the signal, the thread or LWP within the process that is selected to process the signal will execute the signal handler at the specified address. Normally, the signal handler is passed the signal number as its only argument; if the disposition was set with the sigaction() however, additional arguments may be requested (see sigaction(2)). When the signal handler returns, the receiving process resumes execution at the point it was interrupted, unless the signal handler makes other arrangements. If an invalid function address is specified, results are undefined. If the disposition has been set with the sigset() or sigaction(), the signal is automatically blocked in the thread or LWP while it is executing the signal catcher. If a longjmp() is used to leave the signal catcher, then the signal must be explicitly unblocked by the user. See setjmp(3C), signal(3C) and sigprocmask(2). If execution of the signal handler interrupts a blocked function call, the handler is executed and the interrupted function call returns -1 to the calling process with errno set to EINTR. However, if the SA_RESTART flag is set, the function call will be transparently restarted. Some signal-generating functions, such as high resolution timer expiration, asynchronous I/O completion, inter-process message arrival, and the sigqueue(3RT) function, support the specification of an application defined value, either explicitly as a parameter to the function, or in a sigevent structure parameter. The sigevent structure is defined by <signal.h> and contains at least the following members:
The sigval union is defined by <signal.h> and contains at least the following members:
The sigev_notify member specifies the notification mechanism to use when an asynchronous event occurs. The sigev_notify member may be defined with the following values: Your implementation may define additional notification mechanisms. The sigev_signo member specifies the signal to be generated. The sigev_value member references the application defined value to be passed to the signal-catching function at the time of the signal delivery as the si_value member of the siginfo_t structure. The sival_int member is used when the application defined value is of type int, and the sival_ptr member is used when the application defined value is a pointer. When a signal is generated by sigqueue(3RT) or any signal-generating function which supports the specification of an application defined value, the signal is marked pending and, if the SA_SIGINFO flag is set for that signal, the signal is queued to the process along with the application specified signal value. Multiple occurrences of signals so generated are queued in FIFO order. If the SA_SIGINFO flag is not set for that signal, later occurrences of that signal's generation, when a signal is already queued, are silently discarded. SEE ALSOintro(2), _lwp_kill(2), alarm(2), exit(2), getrlimit(2), ioctl(2), kill(2), pause(2), setrctl(2), sigaction(2), sigaltstack(2), sigprocmask(2), sigsend(2), sigsuspend(2), sigwait(2), wait(2), setjmp(3C), siginfo(3HEAD), signal(3C), sigqueue(3RT), sigsetops(3C), thr_create(3THR), thr_kill(3THR), thr_sigsetmask(3THR), ucontext(3HEAD) NOTESThe dispositions of the The Whenever a process receives a SIGSTOP, SIGTSTP, SIGTTIN, or Whenever a process receives a
If the disposition of the SIGCHLD signal has been set with signal or sigset, or with sigaction and the SA_NOCLDSTOP flag has been specified, it will only be sent to the calling process when its children exit; otherwise, it will also be sent when the calling process's children are stopped or continued due to job control. The name The disposition of signals that are inherited as SIG_IGN should not be changed. Signals which are generated synchronously should not be masked. If such a signal is blocked and delivered, the receiving process is killed. NAME | SYNOPSIS | DESCRIPTION | SEE ALSO | NOTES |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||