加入收藏 | 设为首页 | 会员中心 | 我要投稿 威海站长网 (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

/ Establish the signal handler. /
sigfillset (&block_mask);
usr_action.sa_handler = synch_signal;
usr_action.sa_mask = block_mask;
usr_action.sa_flags = 0;
sigaction (SIGUSR1,&usr_action,NULL);

/ Create the child process. /
child_id = fork ();
if (child_id == 0)
child_function (); / Does not return. /

/ Busy wait for the child to send a signal. /
while (!usr_interrupt)
;

/ Now continue execution. /
puts ("That's all,folks!");

return 0;
}

SIG_IGN. But it is useful to block signals briefly,to prevent them from interrupting sensitive operations. For instance:

    You can use thesigprocmaskfunction to block signals while you modify global variables that are also modified by the handlers for these signals.
  • You can setsa_maskin yoursigactioncall to block certain signals while a particular signal handler runs. This way,the signal handler can run without being interrupted itself by signals.

sigprocmaskgives you a way to prevent interrupts during critical parts of your code. If signals arrive in that part of the program,they are delivered later,after you unblock them.

sig_atomic_t(see section),then the signal handler could run when the rest of the program has only half finished reading or writing the data. This would lead to confusing consequences.

sig_atomic_t; you would like to test the flag and perform the action if the flag is not set. This is unreliable. Suppose the signal is delivered immediately after you test the flag,but before the consequent action: then the program will perform the action even though the signal has arrived.

`signal.h'.

sigset_t
Thesigset_tdata type is used to represent a signal set. Internally,it may be implemented as either an integer or structure type.

(编辑:威海站长网)

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

热点阅读