Error in POSIX.pm when using signal handlers 
Author Message
 Error in POSIX.pm when using signal handlers

When I use the below code and run with the'-w' switch I get the following
the first ( and only the first ) time my CHLD signal handler is called:

Argument "CHLD" isn't numeric in subroutine entry at
/usr/local/lib/perl5/5.6.0/alpha-dec_osf/POSIX.pm

Here is a smple script.  It is pretty much textbook code.

------------------------------------------------------
use POSIX ":sys_wait_h";

$SIG{CHLD} = \&sh_child;

# spawn children here

sub sh_child
{
    my $child;

    while( ($child = POSIX::waitpid( -1, &POSIX::WNOHANG )) > 0 )
    {
        # do something with $child and $?
    }

Quote:
}

Anyone have any ideas?  I am using 5.6.0 on DEC's Tru64 Unix.


Mon, 09 Dec 2002 03:00:00 GMT  
 Error in POSIX.pm when using signal handlers

Quote:

> Newsgroups: comp.lang.perl,comp.lang.perl.misc

The newsgroup comp.lang.perl has not existed for many years.    Please
ask your newsadmin to remove it.

Quote:
>When I use the below code and run with the'-w' switch I get the following
>the first ( and only the first ) time my CHLD signal handler is called:

>Argument "CHLD" isn't numeric in subroutine entry at
>/usr/local/lib/perl5/5.6.0/alpha-dec_osf/POSIX.pm

>Here is a smple script.  It is pretty much textbook code.

>------------------------------------------------------
>use POSIX ":sys_wait_h";

>$SIG{CHLD} = \&sh_child;

># spawn children here

>sub sh_child
>{
>    my $child;

>    while( ($child = POSIX::waitpid( -1, &POSIX::WNOHANG )) > 0 )
>    {
>        # do something with $child and $?
>    }

>}

Ouch!    Seeing code like that hurts.

Not that it's your fault  -  Perl has dug a rather {*filter*} pit for you here.

First off:   Signals aren't safe in Perl (yet).    So you should do as
little as possible in a signal handler.    And keep your fingers crossed.

"But I'm doing almost nothing in the signal handler."

True.    But Perl is doing lots of things behind your back.    The
constants in the POSIX module are AUTOLOADed.    So they're only
defined when they are first evaluated.    And that happens in the signal
handler.    So POSIX::AUTOLOAD is called and does various threshing
about ....

Yukkk!

The workaround is to force the constant to be loaded earlier, e.g. by
writing

   use POSIX ":sys_wait_h";
   BEGIN { POSIX::WNOHANG };

Mike Guy



Tue, 10 Dec 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Error in POSIX.pm when using signal handlers

2. Error Message from signal handler or POSIX.pm

3. Signals handlers using POSIX

4. error with signal handler

5. Catching signals within the signal handler

6. EXIT signal for %SIG and signal handlers ?

7. Using message and error handler with syperl

8. POSIX::strftime() error under RH7, perl 5.6.0, POSIX 1.03

9. HELP - errors related to AutoLoader.pm, Entitiy.pm, Internet.pm, IO/Wrap.pm, Head.pm

10. Perl5.000, Solaris 2.3, signal handlers.

11. Signal Handlers

12. signal handlers

 

 
Powered by phpBB® Forum Software