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

while (1) {
register int pid;
int w;
struct process *p;

/* Keep asking for a status until we get a definitive result.  */
do 
  {
    errno = 0;
    pid = waitpid (WAIT_ANY,&w,WNOHANG | WUNTRACED);
  }
while (pid <= 0 &amp;&amp; errno == EINTR);

if (pid <= 0) {
  /* A real failure means there are no more
     stopped or terminated child processes,so return.  */
  errno = old_errno;
  return;
}

/* Find the process that signaled us,and record its status.  */

for (p = process_list; p; p = p->next)
  if (p->pid == pid) {
    p->status = w;
    /* Indicate that the <code>status</code> field
       has data to look at.  We do this only after storing it.  */
    p->have_status = 1;

    /* If process has terminated,stop waiting for its output.  */
    if (WIFSIGNALED (w) || WIFEXITED (w))
      if (p->input_descriptor)
        FD_CLR (p->input_descriptor,&amp;input_wait_mask);

    /* The program should check this flag from time to time
       to see if there is any news in <code>process_list</code>.  */
    ++process_status_change;
  }

/* Loop around to handle all the processes
   that have something to tell us.  */

}
}

process_status_change:

if (process_status_change) {
  struct process *p;
  process_status_change = 0;
  for (p = process_list; p; p = p->next)
    if (p->have_status) {
      ... Examine p->status ...
    }
}

p->statusuntil it sees that status has been validly stored. This is to make sure that the status cannot change in the middle of accessing it. Oncep->have_statusis set,it means that the child process is stopped or terminated,and in either case,it cannot stop or terminate again until the program has taken notice. See section,for more information about coping with interruptions during accessings of a variable.

sig_atomic_t process_status_change;

sig_atomic_t last_process_status_change;

(编辑:威海站长网)

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

热点阅读