Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: fork, %SIG, END.

by Ven'Tatsu (Deacon)
on Aug 19, 2005 at 18:15 UTC ( [id://485251]=note: print w/replies, xml ) Need Help??


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? } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://485251]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-28 13:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found