Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > question on unb...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 11024 of 11060
Post > Topic >>

question on unblocking the signals

by peng.kyo@[EMAIL PROTECTED] (J. Peng) May 4, 2008 at 04:41 PM

Hello,

Please see the code below.
I block the signals in statement 1, and unblocked it in parent
(statement 2) and child (statement 3).
But,  is the statement 2  needed or not?
Should I unblock it once in child or twice in both parent and child?
(if unblocking once is enough, then I believe parent and child will
share the signals).

Thanks!


while (!$DONE)
{
    next unless my $sock = $listen_socket->accept;

    my $signals = POSIX::SigSet->new(SIGHUP,SIGINT,SIGTERM,SIGCHLD);
    sigprocmask(SIG_BLOCK,$signals); # statement 1

    my $child = fork();
    die "[EMERG] can't fork $!\n" unless defined $child;

    if ($child) {
        $status{$child} = 1;
        sigprocmask(SIG_UNBLOCK,$signals); # statement 2

        $sock->close or die "[EMERG] can't close established socket\n";

    } else {
        $SIG{HUP} = $SIG{INT} = $SIG{TERM} = $SIG{CHLD} = 'DEFAULT';
        sigprocmask(SIG_UNBLOCK,$signals); # statement 3

        $listen_socket->close or die "[EMERG] can't close listen
socket\n";

        my $c = <$sock>;
        handle_the_content($c);

        $sock->close or die "[EMERG] can't close established socket\n";

        exit 0;
    }
}

-- 
J. Peng - Peng.Kyo@[EMAIL PROTECTED]
 Chinese Squid supports
http://SquidCN.spaces.live.com/




 1 Posts in Topic:
question on unblocking the signals
peng.kyo@[EMAIL PROTECTED  2008-05-04 16:41:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon May 12 20:21:57 CDT 2008.