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

后端 未结 4 1101
悲&欢浪女
悲&欢浪女 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:00

    See %SIG.

    $SIG{CHLD} = 'IGNORE'; causes your process to ignore SIGCHLD signals.

    $SIG{CHLD} = 'DEFAULT'; causes your process to treat SIGCHLD signals as it would had you not messed with $SIG{CHLD} or equivalent. According to kill(1), a process on my system ignores SIGCHLD by default

    $SIG{CHLD} = ''; and $SIG{CHLD} = undef; are not valid values.

    As for reaping, children of a parent whose SIGCHLD handler is explicitely set to IGNORE will be reaped automatically by the system as soon as it exits.

    $ perl -e'
       my $pid = fork;
       if (!$pid) { sleep(1); exit; }
       sleep(2);
       system "ps -o pid,stat,command $pid";
    '
      PID STAT COMMAND
    14667 ZN+  [perl] 
    
    $ perl -e'
       $SIG{CHLD}="IGNORE";
       my $pid = fork;
       if (!$pid) { sleep(1); exit; }
       sleep(2);
       system "ps -o pid,stat,command $pid";
    '
      PID STAT COMMAND
    
    $
    

提交回复
热议问题