http://qs1969.pair.com?node_id=485251


in reply to fork, %SIG, END.

  1. exit does not create a signal so nothing in %SIG will be called.
  2. Inside a signal handler exit should behave similar to when called elsewhere, as it is possible for most signal handlers to choose not to exit they need to either exit or die themselves.
    Under *nix try (press ctrl+c 5 times to exit)
    perl -e 'my $ccc = 0; $SIG{INT} = sub { $ccc++; print "^C pressed $ccc + times\n"; exit 42 if $ccc >= 5 }; 1 while 1;'; echo $?
  3. One way is to set a flag right after the fork based on what side of the fork you are on.
    my $parentFlag; my $pid = fork(); if ($pid) { #parent process $parentFlag= 1; } elsif (defined $pid) { #child process $parentFlag= 0; } else { #error on fork die "some useful message: $!\n"; } END { if ($parentFlag) { #parent end code } elsif (defined $parentFlag) { #child end code } else { #end block after failed fork or exit before the fork? } }