📄 sigaction.html
字号:
The signal was generated by the completion of anasynchronous I/O request.<dt>SI_MESGQ<dd>The signal was generated by the arrival of a message on anempty message queue.</dl><p>If the signal was not generatedby one of the functions or events listed above, the<i>si_code</i>will be set to an implementation-dependent valuethat is not equal to any of the values defined above.<p>If the Realtime Signals Extension is supported,and<i>si_code</i>is one of SI_QUEUE, SI_TIMER, SI_ASYNCIO, or SI_MESGQ, then<i>si_value</i>contains the application-specified signal value.Otherwise, the contents of<i>si_value</i>are undefined.<p><li>The behaviour of a process is undefined after it returns normallyfrom a signal-catching function for a SIGBUS,SIGFPE, SIGILL or SIGSEGV signal 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>.<p><li>The system will not allow a process to catch the signals SIGKILLand SIGSTOP.<p><li>If a process establishes a signal-catching function for theSIGCHLD signal while it has a terminated child process for whichit has not waited, it is unspecified whether a SIGCHLD signal isgenerated to indicate that child process.<p><li>When signal-catching functions are invoked asynchronously with processexecution, the behaviour of some of the functions defined bythis document is unspecified if they are called from a signal-catchingfunction.<p>The following table defines a set of interfaces that are eitherreentrant or not interruptible by signals and are async-signal safe.Therefore applications may invoke them, withoutrestriction, from signal-catching functions:<p></ul><p></dl><h5><a name = "tag_000_008_581_003"> </a>Base Interfaces</h5><p>_exit()access()alarm()cfgetispeed()cfgetospeed()cfsetispeed()cfsetospeed()chdir()chmod()chown()close()creat()dup()dup2()execle()execve()fcntl()fork()fpathconf()fstat()fsync()getegid()geteuid()getgid()getgroups()getpgrp()getpid()getppid()getuid()kill()link()lseek()mkdir()mkfifo()open()pathconf()pause()pipe()raise()read()rename()rmdir()setgid()setpgid()setsid()setuid()sigaction()sigaddset()sigdelset()sigemptyset()sigfillset ()sigismember()signal()sigpending()sigprocmask()sigsuspend()sleep()stat()sysconf()tcdrain()tcflow()tcflush()tcgetattr()tcgetpgrp()tcsendbreak()tcsetattr()tcsetpgrp()time()times()umask()uname()unlink()utime()wait()waitpid()write()<p><h5><a name = "tag_000_008_581_004"> </a>Realtime Interfaces</h5><p><table <tr valign=top><td align=left><i><i>aio_error</i>()</i><td align=left><i><i>clock_gettime</i>()</i><td align=left><i><i>sigpause</i>()</i><td align=left><i><i>timer_getoverrun</i>()</i><tr valign=top><td align=left><i><i>aio_return</i>()</i><td align=left><i><i>fdatasync</i>()</i><td align=left><i><i>sigqueue</i>()</i><td align=left><i><i>timer_gettime</i>()</i><tr valign=top><td align=left><i><i>aio_suspend</i>()</i><td align=left><i><i>sem_post</i>()</i><td align=left><i><i>sigset</i>()</i><td align=left><i><i>timer_settime</i>() </i></table><p>All functions not in the above table are considered to be unsafewith respect to signals.In the presence of signals, all functions defined by this specificationwill behave as defined when called from or interrupted by a signal-catchingfunction, with a single exception: when a signal interrupts an unsafefunction andthe signal-catching function calls an unsafe function, the behaviouris undefined.<p></><p></><p>When a signal is delivered to a thread,if the action of that signal specifies termination, stop, or continue,the entire process will be terminated, stopped, or continued,respectively.<h5><a name = "tag_000_008_581_005"> </a>Signal Effects on Other Functions</h5>Signals affect the behaviour of certain functions defined by thisspecification if delivered to a process while it is executing such afunction.If the action of the signal is to terminate the process, theprocess will be terminated and the function will not return.If the action of the signal is to stop the process, the processwill stop until continued or terminated.Generation of a SIGCONT signal for the process causes the processto be continued, and the original function will continue at the pointthe process was stopped.If the action of the signal is to invoke a signal-catchingfunction, the signal-catching function will be invoked; in thiscase the original function is said to be<i>interrupted</i>by the signal.If the signal-catching function executes a<b>return</b>statement,the behaviour of the interrupted function will be as describedindividually for that function.Signals that are ignored will not affect the behaviour of anyfunction; signals that are blocked will not affect the behaviourof any function until they are unblocked and then delivered,except as specified for the<i><a href="sigpending.html">sigpending()</a></i>and the <i><a href="sigwait.html">sigwait()</a></i>functions.<p>The result of the use of<i>sigaction()</i>and a<i><a href="sigwait.html">sigwait()</a></i>function concurrently within a process on the same signal isunspecified.</blockquote><h4><a name = "tag_000_008_582"> </a>RETURN VALUE</h4><blockquote>Upon successful completion,<i>sigaction()</i>returns 0. Otherwise -1 is returned,<i>errno</i>is set to indicate the error and no new signal-catching functionwill be installed.</blockquote><h4><a name = "tag_000_008_583"> </a>ERRORS</h4><blockquote>The<i>sigaction()</i>function will fail if:<dl compact><dt>[EINVAL]<dd>The<i>sig</i>argument is not a valid signal number or an attempt is made tocatch a signal that cannot be caught or ignore a signal thatcannot be ignored.</dl><p>The<i>sigaction()</i>function may fail if:<dl compact><dt>[EINVAL]<dd>An attempt was made to set the action to SIG_DFL for a signalthat cannot be caught or ignored (or both).</dl></blockquote><h4><a name = "tag_000_008_584"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_008_585"> </a>APPLICATION USAGE</h4><blockquote>The<i>sigaction()</i>function supersedes the<i><a href="signal.html">signal()</a></i>interface, and should be used in preference. In particular,<i>sigaction()</i>and<i><a href="signal.html">signal()</a></i>should not be used in the same process to control the same signal.The behaviour of reentrant interfaces, as defined in thedescription,is as specified by this specification, regardless of invocation from asignal-catching function.This is the only intended meaning of the statement that reentrantinterfaces may be used in signal-catching functions withoutrestrictions.Applications must still consider all effects of such functions onsuch things as data structures, files and process state.In particular, application writers need to consider therestrictions on interactions when interrupting<i><a href="sleep.html">sleep()</a></i>and interactions among multiple handles for a file description.The fact that any specific interface is listed as reentrant doesnot necessarily mean that invocation of that interface from asignal-catching function is recommended.<p>In order to prevent errors arising from interruptingnon-reentrant function calls, applications should protect callsto these functions either by blocking the appropriate signals orthrough the use of some programmatic semaphore (see<i><a href="semget.html">semget()</a></i>,<i><a href="sem_init.html">sem_init()</a></i>,<i><a href="sem_open.html">sem_open()</a></i>,and so on).Note in particular that even the "safe" functions may modify<i>errno</i>;the signal-catching function, if not executing as an independentthread, may want to save and restore its value.Naturally, the same principles apply to the reentrancy ofapplication routines and asynchronous data access.Note that<i><a href="longjmp.html">longjmp()</a></i>and<i><a href="siglongjmp.html">siglongjmp()</a></i>are not in the list of reentrant interfaces.This is because the code executing after<i><a href="longjmp.html">longjmp()</a></i>and<i><a href="siglongjmp.html">siglongjmp()</a></i>can call any unsafe functions with the same danger as calling thoseunsafe functions directly from the signal handler.Applications that use<i><a href="longjmp.html">longjmp()</a></i>and<i><a href="siglongjmp.html">siglongjmp()</a></i>from within signal handlers require rigorous protection in order to beportable.Many of the other functions that are excluded from the list aretraditionally implemented using either<i><a href="malloc.html">malloc()</a></i>or<i><a href="free.html">free()</a></i>functions or the standard I/O library, both of whichtraditionally use data structures in a non-reentrant manner.Because any combination of different functions using a commondata structure can cause reentrancy problems, this document does notdefine the behaviour when any unsafefunction is called in a signal handler that interrupts an unsafe function.<p>If the signal occurs other than as the result of calling<i><a href="abort.html">abort()</a></i>,<i><a href="kill.html">kill()</a></i>or<i><a href="raise.html">raise()</a></i>,the behaviour is undefined if the signal handler callsany function in the standard library other than one of thefunctions listed in the table aboveor refers to any object with static storage durationother than by assigning a value to a static storage durationvariable of type<b>volatile</b><b>sig_atomic_t</b>.Furthermore, if such a call fails,the value of<i>errno</i>is indeterminate.<p>Usually, the signal is executed on the stack that was in effect before thesignal was delivered. An alternate stack may be specified to receive a subsetof the signals being caught.<p>When the signal handler returns, the receiving process will resume executionat the point it was interrupted unless the signal handler makes otherarrangements. If<i><a href="longjmp.html">longjmp()</a></i>or<i><a href="_longjmp.html">_longjmp()</a></i>is used to leave the signal handler, then the signal mask must be explicitlyrestored by the process.<p>The ISO POSIX-1 standard defines the third argument of a signal handling function whenSA_SIGINFO is set as a <b>void *</b> instead of a <b>ucontext_t *</b>,but without requiring type checking. New applications should explicitly castthe third argument of the signal handling function to <b>ucontext_t *</b>.<p>The BSD optional four argument signal handling function is not supported bythis specification. The BSD declaration would be:<pre><code>void handler(int <i>sig</i>, int <i>code</i>, struct sigcontext *<i>scp</i>, char *<i>addr</i>);</code></pre><p>where <i>sig</i> is the signal number, <i>code</i> is additional information oncertain signals, <i>scp</i> is a pointer to the sigcontext structure, and<i>addr</i> is additional address information. Much the same information isavailable in the objects pointed to by the second argument of thesignal handler specified when SA_SIGINFO is set.</blockquote><h4><a name = "tag_000_008_586"> </a>FUTURE DIRECTIONS</h4><blockquote>The<i><a href="fpathconf.html">fpathconf()</a></i>function is marked as an extension in the list of safe functionsbecause it is not included in the corresponding list in the ISO POSIX-1 standard,but it is expected to be added in a future revision of thatstandard.</blockquote><h4><a name = "tag_000_008_587"> </a>SEE ALSO</h4><blockquote><i><a href="bsd_signal.html">bsd_signal()</a></i>,<i><a href="kill.html">kill()</a></i>,<i><a href="_longjmp.html">_longjmp()</a></i>,<i><a href="longjmp.html">longjmp()</a></i>,<i><a href="raise.html">raise()</a></i>,<i><a href="semget.html">semget()</a></i>,<i><a href="sem_init.html">sem_init()</a></i>,<i><a href="sem_open.html">sem_open()</a></i>,<i><a href="sigaddset.html">sigaddset()</a></i>,<i><a href="sigaltstack.html">sigaltstack()</a></i>,<i><a href="sigdelset.html">sigdelset()</a></i>,<i><a href="sigemptyset.html">sigemptyset()</a></i>,<i><a href="sigfillset.html">sigfillset()</a></i>,<i><a href="sigismember.html">sigismember()</a></i>,<i><a href="signal.html">signal()</a></i>,<i><a href="sigprocmask.html">sigprocmask()</a></i>,<i><a href="sigsuspend.html">sigsuspend()</a></i>,<i><a href="wait.html">wait()</a></i>,<i><a href="wait3.html">wait3()</a></i>,<i><a href="waitid.html">waitid()</a></i>,<i><a href="waitpid.html">waitpid()</a></i>,<i><a href="signal.h.html"><signal.h></a></i>,<i><a href="ucontext.h.html"><ucontext.h></a></i>.<br></blockquote><h4>DERIVATION</h4><blockquote>Derived from the POSIX.1-1988 standard.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -