Handling SIGCHLD, how to record the return values of children as they die

后端 未结 2 511
感动是毒
感动是毒 2021-01-03 12:07
void childSignalHandler(int signo) {
    int status;

    pid_t pid = wait(&status);

    struct PIDList* record = getRecordForPID(childlist, pid);
    if (recor         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-03 12:38

    This should do the job, if you set your function as a handler for SIGCHLD.

    However, SIGCHLD can be send to parent process not only after the child exited. Some other events are signaled this way as well (for instance when the child is stopped). See man wait(3) for detailed explanation.

提交回复
热议问题