⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sigaction.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
📖 第 1 页 / 共 3 页
字号:
unspecified whether the signal is discarded immediately upongeneration or remains pending.<p>Each thread has a<i>signal mask</i>that defines the set of signals currently blocked from deliveryto it.The signal mask for a thread is initialised from that of itsparentor creating thread, or from the corresponding thread in the parentprocess if the thread was created as the result of a call to<i><a href="fork.html">fork()</a></i>.The<i>sigaction()</i>,<i><a href="sigprocmask.html">sigprocmask()</a></i>and<i><a href="sigsuspend.html">sigsuspend()</a></i>functions control the manipulation of the signal mask.<p>The determination of which action is taken in response to asignal is made at the time the signal is delivered, allowing forany changes since the time of generation.This determination is independent of the means by which thesignal was originally generated.If a subsequent occurrence of a pending signal is generated, itis implementation-dependent as to whether the signal is deliveredor accepted more than once in circumstancesother than thosein which queueing is required under the Realtime Signals Extension option.The order in which multiple, simultaneously pending signalsoutside the range SIGRTMIN to SIGRTMAX are delivered to or accepted bya process is unspecified.<p>When any stop signal (SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU) isgenerated for a process, any pending SIGCONT signals for thatprocess will be discarded.Conversely, when SIGCONT is generated for a process, all pendingstop signals for that process will be discarded.When SIGCONT is generated for a process that is stopped, theprocess will be continued, even if the SIGCONT signal is blockedor ignored.If SIGCONT is blocked and not ignored, it will remain pendinguntil it is either unblocked or a stop signal is generated forthe process.<p>An implementation will document any condition not specified bythis document under which the implementation generates signals.<p>Some signal-generating functions, such ashigh-resolution timer expiration,asynchronous I/O completion, interprocess message arrival, and the<i><a href="sigqueue.html">sigqueue()</a></i>function,support the specification of an application-defined value,either explicitly as a parameter to the function or in a<b>sigevent</b> structure parameter.The <b>sigevent</b> structure is defined in<i><a href="signal.h.html">&lt;signal.h&gt;</a></i>and contains at least the following members:<p><table  bordercolor=#000000 border=1 align=center><tr valign=top><th align=center><b>Member Type</b><th align=center><b>Member Name</b><th align=center><b>Description</b><tr valign=top><td align=left>int<td align=left>sigev_notify<td align=left>Notification type<tr valign=top><td align=left>int<td align=left>sigev_signo<td align=left>Signal number<tr valign=top><td align=left>union sigval<td align=left>sigev_value<td align=left>Signal value<tr valign=top><td align=left>void(*)(unsigned sigval)<td align=left>sigev_notify_function<td align=left>Notification function<tr valign=top><td align=left>(pthread_attr_t*)<td align=left>sigev_notify_attributes<td align=left>Notification attributes</table><p>The <i>sigev_notify</i>member specifies the notification mechanism to usewhen an asynchronous event occurs.This document defines the following values for the<i>sigev_notify</i>member:<dl compact><dt>SIGEV_NONE<dd>No asynchronous notification will be deliveredwhen the event of interest occurs.<dt>SIGEV_SIGNAL<dd>The signal specified in<i>sigev_signo</i>will be generated for the process when the event of interest occurs.If the implementation supports the Realtime Signals Extension optionand if the SA_SIGINFO flag is set for that signal number, then the signalwill be queued to the process and the value specified in<i>sigev_value</i>will be the<i>si_value</i>component of the generated signal.If SA_SIGINFO is not set for that signal number, it is unspecified whetherthe signal is queued and what value, if any, is sent.<dt>SIGEV_THREAD<dd>A notification function will be called to perform notification.</dl><p>An implementation may define additional notification mechanisms.<p>The<i>sigev_signo</i>member specifies the signal to be generated.The<i>sigev_value</i>member is the application-defined valueto be passed to the signal-catching functionat the time of the signal deliveryor to be returned at signal acceptance as the<i>si_value</i>member of the<b>siginfo_t</b>structure.<p>The<b>sigval</b>union is defined in<i><a href="signal.h.html">&lt;signal.h&gt;</a></i>and contains at least the following members:<p><table  bordercolor=#000000 border=1 align=center><tr valign=top><th align=center><b>Member Type</b><th align=center><b>Member Name</b><th align=center><b>Description</b><tr valign=top><td align=left>int<td align=left>sival_int<td align=left>Integer signal value<tr valign=top><td align=left>void*<td align=left>sival_ptr<td align=left>Pointer signal value</table><p>The<i>sival_int</i>member is used when the application-defined value is of type<b>int</b>;the<i>sival_ptr</i>member is used when the application-defined value is a pointer.<p>If the Realtime Signals Extension option is supported:<dl compact><dt> <dd>When a signal is generated by the<i><a href="sigqueue.html">sigqueue()</a></i>functionor any signal-generating function that supports the specificationof an application-defined value,the signal will be marked pending and, if the SA_SIGINFOflag is set for that signal, the signal will be queued to the processalong with the application-specified signal value.Multiple occurrences of signals so generated are queued in FIFOorder.It is unspecified whether signals so generated are queued when theSA_SIGINFO flag is not set for that signal.<p>Signals generated by the<i><a href="kill.html">kill()</a></i>function or other events that cause signals to occur,such as detection of hardware faults,<i><a href="alarm.html">alarm()</a></i>timer expiration, or terminal activity,and for which the implementation does not support queuing,have no effect on signals already queued for the same signalnumber.</dl><dl compact><dt> <dd>When multiple unblocked signals, all in the rangeSIGRTMIN to SIGRTMAX, are pending,the behaviour will be as ifthe implementation delivers the pending unblocked signalwith the lowest signal number within that range.No other ordering of signal delivery is specified.<p>If, when a pending signal is delivered,there are additional signals queued to that signal number,the signal remains pending.Otherwise, the pending indication is reset.</dl><p>Multi-threaded programs can use an alternate event notificationmechanism:<dl compact><dt> <dd>When a notification is processed, and the<i>sigev_notify</i>member of the<b>sigevent</b>structure has the value SIGEV_THREAD, the function<i>sigev_notify_function</i>is called with parameter<i>sigev_value</i>.<p>The function will be executed in an environmentas if it were the<i>start_routine</i>for a newly created thread with thread attributes specified by<i>sigev_notify_attributes</i>.If<i>sigev_notify_attributes</i>is NULL, the behaviour will as if the thread were created with the<i>detachstate</i>attribute set to PTHREAD_CREATE_DETACHED.Supplying an attributes structure with a<i>detachstate</i>attribute of PTHREAD_CREATE_JOINABLEresults in undefined behaviour.The signal mask of this thread is implementation-dependent.</dl><h5><a name = "tag_000_008_581_002">&nbsp;</a>Signal Actions</h5><xref type="5" name="sigact"></xref>There are three types of action that can be associated with asignal: SIG_DFL, SIG_IGN or a<i>pointer to a function</i>.Initially, all signals will be set to SIG_DFL or SIG_IGN prior toentry of the<i>main()</i>routine (see the<i>exec</i>functions).The actions prescribed by these values are as follows:<dl compact><dt>SIG_DFL - signal-specific default action<dd><ul><li>The default actions for the signals defined in this specification arespecified under<i><a href="signal.h.html">&lt;signal.h&gt;</a></i>.If the Realtime Signals Extension option is supported,the default actions for the realtime signals in the range SIGRTMIN toSIGRTMAX are to terminate the process abnormally.<li>If the default action is to stop the process, the execution ofthat process is temporarily suspended.When a process stops, a SIGCHLD signal will be generated for itsparent process, unless the parent process has set theSA_NOCLDSTOP flag.While a process is stopped, any additional signals that are sentto the process will not be delivered until the process iscontinued, except SIGKILL which always terminates the receivingprocess.A process that is a member of an orphaned process group will notbe allowed to stop in response to the SIGTSTP, SIGTTIN orSIGTTOU signals.In cases where delivery of one of these signals would stop such aprocess, the signal will be discarded.<li>Setting a signal action to SIG_DFL for a signal that is pending,and whose default action is to ignore the signal (for example, SIGCHLD),will cause the pending signal to be discarded, whether or not itis blocked.If the Realtime Signals Extension option is supported,any queued values pending will be discarded and the resources used toqueue them will be released and made available to queue other signals.</ul><dt>SIG_IGN - ignore signal<dd><ul><li>Delivery of the signal will have no effect on the process.The behaviour of a process is undefined after it ignores aSIGFPE, SIGILL, SIGSEGV or SIGBUSsignal that was not generated by<i><a href="kill.html">kill()</a></i>,<i><a href="sigqueue.html">sigqueue()</a></i>or<i><a href="raise.html">raise()</a></i>.<li>The system will not allow the action for the signals SIGKILL orSIGSTOP to be set to SIG_IGN.<li>Setting a signal action to SIG_IGN for a signal that is pendingwill cause the pending signal to be discarded, whether or not itis blocked.<li>If a process sets the action for the SIGCHLD signal to SIG_IGN,the behaviour is unspecified,except as specified below.If the action for the SIGCHLD signal is set to SIG_IGN,child processes of the calling processes will not be transformed into zombieprocesseswhen they terminate.  If the calling process subsequently waits for itschildren, and the process has no unwaited for children that were transformedinto zombie processes, it will block until all of its children terminate, and<i><a href="wait.html">wait()</a></i>,<i><a href="wait3.html">wait3()</a></i>,<i><a href="waitid.html">waitid()</a></i>and<i><a href="waitpid.html">waitpid()</a></i>will fail and set<i>errno</i>to [ECHILD].If the Realtime Signals Extension option is supported,any queued values pending will be discarded and the resources used toqueue them will be released and made available to queue other signals.</ul><dt><i>pointer to a function</i> - catch signal<dd><ul><li>On delivery of the signal, the receiving process is to executethe signal-catching function at the specified address.After returning from the signal-catching function, the receivingprocess will resume execution at the point at which it wasinterrupted.If the SA_SIGINFOflag for the signal is cleared, the signal-catching functionwill be entered as a C language function call as follows:<pre><code>void <i>func</i>(int <i>signo</i>);</code></pre>If the SA_SIGINFO flag for the signal is set, the signal-catching function will be entered as a C language function call as follows:<pre><code>void <i>func</i>(int <i>signo</i>, siginfo_t *<i>info</i>, void *<i>context</i>);</code></pre>where<i>func</i>is the specified signal-catching function,<i>signo</i>is the signal number of the signal being delivered, and<i>info</i>is a pointer to a<b>siginfo_t</b>structure defined in<i><a href="signal.h.html">&lt;signal.h&gt;</a></i>containing at least the following member(s):<table  bordercolor=#000000 border=1 align=center><tr valign=top><th align=center><b>Member Type</b><th align=center><b>Member Name</b><th align=center><b>Description</b><tr valign=top><td align=left>int<td align=left>si_signo<td align=left>Signal number<tr valign=top><td align=left>int<td align=left>si_code<td align=left>Cause of the signal<tr valign=top><td align=left>union sigval<td align=left>si_value<td align=left>Signal value</table>The<i>si_signo</i>member contains the signal number.This is the same as the<i>signo</i>parameter.The<i>si_code</i>member contains a code identifying the cause of the signal.The following values are defined for<i>si_code</i>:<dl compact><dt>SI_USER<dd>The signal was sent by the<i><a href="kill.html">kill()</a></i>function.The implementation may set<i>si_code</i>to SI_USER if the signal was sent by the<i><a href="raise.html">raise()</a></i>or<i><a href="abort.html">abort()</a></i>functionsor any similar functions provided as implementation extensions.<dt>SI_QUEUE<dd>The signal was sent by the<i><a href="sigqueue.html">sigqueue()</a></i>function.<dt>SI_TIMER<dd>The signal was generated by the expiration of a timer set by<i><a href="timer_settime.html">timer_settime()</a></i>.<dt>SI_ASYNCIO<dd>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -