简体   繁体   English

哪个子进程发送SIGCHLD

[英]Which child process send SIGCHLD

I'm trying to understand the signal handling and process. 我正在尝试了解信号处理和过程。 I have a parent process that created several child processes. 我有一个创建多个子进程的父进程。 Now in the parent process I have a list of all child processes. 现在,在父进程中,我具有所有子进程的列表。 when a child is terminated I want to delete it from the list. 当孩子终止时,我想从列表中删除它。 I know that when a child is terminated he's sending SIGCHLD to the parent. 我知道,当孩子被解雇时,他正在将SIGCHLD发送给父母。 OK, now it's the tricky part, how can I find out if that child terminated or just suspended or something else? 好吧,现在这是棘手的部分,我如何才能知道那个孩子是被解雇还是刚刚被停职?

As you said 如你所说

when a child is terminated he's sending SIGCHLD to the parent 当孩子被解雇时,他正在将SIGCHLD发送给父母

Make the parent call wait() . 使父级调用wait()

Either 要么

  • by a blocking call to wait() or 通过阻塞调用wait()
  • on a continous base or 在连续的基础上
  • by seting up a signal handler serving SIGCHLD which in turn calls wait() . 通过设置服务SIGCHLD的信号处理程序,依次调用wait()

If having called waitpid() with a pid of -1 using the option WUNTRACED and then applying the macro WIFSTOPPED to the value returend by waitpid() it tells you whether the process was stopped or ended. 如果使用选项WUNTRACED调用了pid值为-1 waitpid() ,然后将WIFSTOPPEDWIFSTOPPED waitpid()返回的值,它将告诉您该进程是停止还是结束。

For Linux since kernel version 2.6.10 the same as for WIFSTOPPED applies to WCONTINUED . 对于从2.6.10内核版本开始的Linux,与WIFSTOPPED相同,适用于WCONTINUED

There is a system call in signal.h - sigaction() , similar to siganl( ) but more useful. signal.h - sigaction()中有一个系统调用,类似于siganl(),但更有用。
Visit http://man7.org/linux/man-pages/man2/sigaction.2.html 访问http://man7.org/linux/man-pages/man2/sigaction.2.html

The signal handler function prototype for sigaction() looks like this: sigaction()的信号处理程序函数原型如下所示:

void sa_handler(int signo, siginfo_t *si, void *ucontext);

It has an argument of type siginfo_t which contains all the information about the signal including the pid of the process which sent it. 它的参数类型为siginfo_t,其中包含有关信号的所有信息,包括发送信号的进程的pid。
Though using conventional signal handling mechanism, it can be done using waitid() as mentioned in previous answer(s) but waitid() needs pid as one of its argument. 尽管使用常规的信号处理机制,但是可以使用前面的答案中提到的waitid()来完成,但是waitid()需要使用pid作为其参数之一。

Using the options argument of the wait() family of functions (waitpid(),waitid()). 使用wait()函数系列的参数(waitpid(),waitid())。

http://linux.die.net/man/2/waitid http://linux.die.net/man/2/waitid

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM