Pb $SIG{CHLD}=sub{wait()}; in Perl 5.8.0

Discussion in 'Perl Misc' started by Sébastien Cottalorda, Aug 1, 2003.

  1. Hi all,

    Since I migrate a Perl Socket application from perl 5.6.0 to 5.8.0, I
    encoutered problem with the $SIG{CHLD} interrupt.

    Here is sample of my code (server side):

    use IO::Socket;
    my $port_recep=12345;
    my ($server, $client);
    my ($port,$iaddr);
    my $server= IO::Socket::INET->new(LocalPort=> $port_recep,
    Type=> SOCK_STREAM,
    Reuse=>1,
    Listen=>10)
    or die "Couln\'t be a tcp server on $port_recep $@\n";

    $SIG{CHLD} = sub { wait () };
    while ($client=$server->accept()) {
    $pid = fork ();
    unless (defined($pid)) {
    print "Impossible to fork : $!";
    exit 1;
    }
    if ($pid == 0){
    $port = $client->peerport();
    $iaddr= $client->peerhost();
    print "Connexion accepted from $iaddr on port $port\n";
    # do the treatment ....
    print "Son has finished\n";
    close($client);
    exit;
    }
    }
    print "Father has finished. It\'s not normal\n";
    close($server);
    exit 0;


    When a connexion cames, it was taken by the son, and the father dies just
    after the son has finished his job.

    If someone has a clue.

    Thanks in advance.

    Sébastien
     
    Sébastien Cottalorda, Aug 1, 2003
    #1
    1. Advertising

  2. Stefan wrote:

    > "Sébastien Cottalorda" <> schreef in bericht
    > news:3f2a7617$0$19516$...
    >> Hi all,
    >>
    >> Since I migrate a Perl Socket application from perl 5.6.0 to 5.8.0, I
    >> encoutered problem with the $SIG{CHLD} interrupt.
    >>
    >> Here is sample of my code (server side):

    >
    > /--- snip code ---/
    >
    >> When a connexion cames, it was taken by the son, and the father dies just
    >> after the son has finished his job.
    >>
    >> If someone has a clue.
    >>
    >> Thanks in advance.
    >>
    >> Sébastien

    >
    >
    > It might be related to the fact the different versions of Perl handle
    > calls differently. Don't ask me about the underlaying details - try a
    > Google/Groups search on "Perl EINTR" and/or "Perl EINTR accept".
    >
    > In your code, you don't really check the status of the accept() call. If
    > you do, you'll probably see that accept() return status-code 4 (EINTR). In
    > my experience, that never happens the 1st time a connection is accepted.
    > That may explain that the father dies after the son has completed.
    >
    > Try adding some accept() status handling - this is a piece of code I use;
    >
    > use Errno 'EINTR'; # or use a constant value of 4
    >
    > ClientAccept: {
    > $client = $server->accept();
    > if ($! == EINTR) {
    > if ($client) {
    > print "Non-fatal Interrupted system call in accept()\n";
    > } else {
    > print "Interrupted system call - redo accept()\n";
    > redo ClientAccept;
    > }
    > }
    >
    > # --- rest of your server-code
    > }
    >
    > Good luck,
    > Stefan



    Thanks Stefan.
    I'll check your proposal.

    Sébastien
     
    Sébastien Cottalorda, Aug 1, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben
    Replies:
    2
    Views:
    919
  2. matchstick86

    sig : process vs. process(sig)

    matchstick86, Oct 12, 2009, in forum: VHDL
    Replies:
    1
    Views:
    571
    power_hf2005
    Oct 13, 2009
  3. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    2,083
    Lawrence D'Oliveiro
    May 20, 2011
  4. Heinrich Mislik

    $SIG{CHLD} and system

    Heinrich Mislik, Sep 30, 2004, in forum: Perl Misc
    Replies:
    5
    Views:
    166
    Heinrich Mislik
    Oct 1, 2004
  5. Eric Pozharski

    Selective $SIG{CHLD}

    Eric Pozharski, Nov 23, 2010, in forum: Perl Misc
    Replies:
    0
    Views:
    103
    Eric Pozharski
    Nov 23, 2010
Loading...

Share This Page