处理SIGCHLD,如何记录孩子死亡时的返回值 [英] Handling SIGCHLD, how to record the return values of children as they die

查看:94
本文介绍了处理SIGCHLD,如何记录孩子死亡时的返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void childSignalHandler(int signo) {
    int status;

    pid_t pid = wait(&status);

    struct PIDList* record = getRecordForPID(childlist, pid);
    if (record != NULL)
        record->returnValue = status;
}

快速提问:

我希望此处理程序在一个孩子死亡时(该应用程序产生许多孩子),获取他们的返回值并记录下来(最后三行).是这样做吗,还是我把所有这些API业务都弄错了?

I want this handler to, when a child dies (this app spawns lots of children), get their return value and record it (last three lines). Will this do it, or am I getting all this API business wrong?

谢谢您的时间!

(此外,Linux API术语令人毛骨悚然,请检查即将死去的孩子和其他人)

(also, linux API terminology is creepy as hell, check for dying children and whatnot)

推荐答案

如果将函数设置为SIGCHLD的处理程序,则此工作即可完成.

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

但是,SIGCHLD不仅可以在孩子退出后发送给父进程 .其他一些事件也以这种方式发出信号(例如,当孩子停止活动时).有关详细说明,请参见 man wait(3).

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.

这篇关于处理SIGCHLD,如何记录孩子死亡时的返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆