What's the difference between various $SIG{CHLD} values?

后端 未结 4 1107
悲&欢浪女
悲&欢浪女 2020-12-16 22:22

What is the difference between these settings?

$SIG{CHLD} = \'IGNORE\'  
$SIG{CHLD} = \'DEFAULT\'  
$SIG{CHLD} = \'\'  
$SIG{CHLD} = undef

4条回答
  •  情书的邮戳
    2020-12-16 23:14

    There are two different meaning for "ignore", and they are occurring at two different points of evaluation.

    The first use concerns whether to deliver the signal at all. When a child processes exits, it usually is held by the operating system and a CHLD signal is sent to its parent. When setting $SIG{CHLD} to 'IGNORE', it tells the system to not generate a signal at all and just let the child process exit. The parent has no opportunity to get information on the child process, and no zombies result.

    But if $SIG{CHLD} is anything other than 'IGNORE', it means to deliver the signal to the parent process, at which point there is either a custom signal handler or a default signal handler, and the default handler will vary on different systems or even versions of the same operating system. The book and signal(7) man page talk about what happens by default if a signal is delivered to the parent process (i.e. handler is not set to 'IGNORE'). So the second use of ignore is related to which action to take for a delivered signal. For example SIGINT will cause your process to be terminated, and SIGSTOP will cause your process to "pause", although custom signal handlers change these default actions.

    For the SIGCHLD signal, the default is to "ignore" it, but in this usage it just means the (parent) process just continues executing normally while the child process waits (i.e. no termination or aborting of parent process). You can then wait() on it later to get it's information and avoid a zombie.

提交回复
热议问题