开发者

Using sigaction for SIGCHLD to know when children terminate but unable to tell when the child SIGSEVs

According to the man page for sigaction, 开发者_运维知识库if we use it with SIGCHLD then in our handler function - this is if we use void (*sa_sigaction)(int, siginfo_t *, void *);

the si_code member of the siginfo_t structure should contain the reason the signal was sent.

I am interested in these reasons...

CLD_EXITED
CLD_KILLED
CLD_DUMPED

Now my question is... even if the child exited abnormally (i.e by executing buggy code to cause a crash) i still get CLD_EXITED. I assumed I should get CLD_DUMPED instead. As for CLD_KILLED, if I kill a child process, I get this one correctly.

What am I missing? In my parent process, I need to know if any of the child processes terminate abruptly.

I am causing the abrupt error by trying to write to a null pointer but I need to know of any kind of abnormal termination. It is not necessary to know exactly what or how it happened.

When is the CLD_DUMPED generated?

Kind Regards.


Rather than the si_code given to the signal handler, you should simply be looking at the exit status from waitpid (or one of the other wait-family functions) to determine the cause of exit. The macros W* from sys/wait.h, when applied to the status int, will tell you the cause of termination.


AFAIK, CLD_DUMPED is caused when the process dumps core.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜