Avoiding a fork()/SIGCHLD race condition

后端 未结 4 1147
情话喂你
情话喂你 2020-12-17 16:12

Please consider the following fork()/SIGCHLD pseudo-code.

  // main program excerpt
    for (;;) {
      if ( is_time_to_make_babie         


        
4条回答
  •  暖寄归人
    2020-12-17 16:38

    Simplest solution would be to block SIGCHLD signal before fork() with sigprocmask() and unblock it in parent code after you have processed the pid.

    If child died, signal handler for SIGCHLD will be called after you unblock the signal. It is a critical section concept - in your case critical section starts before fork() and ends after children.add().

提交回复
热议问题