加入收藏 | 设为首页 | 会员中心 | 我要投稿 威海站长网 (https://www.0631zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

Signal Handling--ref

发布时间:2021-01-25 08:01:09 所属栏目:Linux 来源:网络整理
导读:signal is a software interrupt delivered to a process. The operating system uses signals to report exceptional situations to an executing program. Some signals report errors such as references to invalid memory addresses; others report asy

The value returned byTEMP_FAILURE_RETRYis whatever valueexpressionproduced.

EINTRentirely and provides a more convenient approach: to restart the interrupted primitive,instead of making it fail. If you choose this approach,you need not be concerned withEINTR.

sigactionto establish a signal handler,you can specify how that handler should behave. If you specify theSA_RESTARTflag,return from that handler will resume a primitive; otherwise,return from that handler will causeEINTR. See sectionsigaction.

siginterruptfunction. See section.

sigactionorsiginterruptwhat a particular handler should do,it uses a default choice. The default choice in the GNU library depends on the feature test macros you have defined. If you define_BSD_SOURCEor_GNU_SOURCEbefore callingsignal,the default is to resume primitives; otherwise,the default is to make them fail withEINTR. (The library contains alternate versions of thesignalfunction,and the feature test macros determine which one you really call.) See section.

EINTRamong the error codes it can return.

readorwriteis interrupted by a signal after transferring part of the data. In this case,the function returns the number of bytes already transferred,indicating partial success.

readorwriteinto two would read or write two records. Actually,there is no problem,because interruption after a partial transfer cannot happen on such devices; they always transfer an entire record in one burst,with no waiting once data transfer has started.

raisefunction. This function is declared in`signal.h'.

intraise(intsignum)
Theraisefunction sends the signalsignumto the calling process. It returns zero if successful and a nonzero value if it fails. About the only reason for failure would be if the value ofsignumis invalid.
intgsignal(intsignum)
Thegsignalfunction does the same thing asraise; it is provided only for compatibility with SVID.

raiseis to reproduce the default behavior of a signal that you have trapped. For instance,suppose a user of your program types the SUSP character (usuallyC-z; see section) to send it an interactive stop stop signal (SIGTSTP),and you want to clean up some internal data buffers before stopping. You might set this up like this:

#include 

/ When a stop signal arrives,set the action back to the default
and then resend the signal after doing cleanup actions.
/

void
tstp_handler (int sig)
{
signal (SIGTSTP,SIG_DFL);
/ Do cleanup actions here. /
...
raise (SIGTSTP);
}

/ When the process is continued again,restore the signal handler. /

void
cont_handler (int sig)
{
signal (SIGCONT,cont_handler);
signal (SIGTSTP,tstp_handler);
}

/ Enable both handlers during program initialization. /

(编辑:威海站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读