develooper Front page | perl.perl5.porters | Postings from April 2004

[perl #29012] Manipulating hash in SIGCHLD handler causes "Segmentation fault"

From:
Mao Morimoto
Date:
April 28, 2004 04:53
Subject:
[perl #29012] Manipulating hash in SIGCHLD handler causes "Segmentation fault"
Message ID:
rt-3.0.8-29012-85761.12.2494523317651@perl.org
# New Ticket Created by  "Mao Morimoto" 
# Please include the string:  [perl #29012]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=29012 >


This is a bug report for perl from morimoto@interlink.ad.jp,
generated with the help of perlbug 1.26 running under perl 5.008003.


-----------------------------------------------------------------
[Please enter your report here]

Manipulating hash in signal handler (SIGCHLD) causes "Segmentation fault".
Run following script some times. "Segmentation fault" may happen at "POINT1"
or "POINT2".

$speed = 0.001 ; # more fast more error

$SIG{CHLD} = sub {
        while ( (my $pid = waitpid( -1, WNOHANG )) > 0 ) {
                if ( exists $children{$pid} ) {
                        delete $children{$pid} ;
                } else {
                        print "no such pid in the hash! ($pid)\n" ;
                }
        }
} ;

for ( my $i = 0 ; $i < 1000 ; $i++ ) {
        my $pid = fork ;
        if ( !defined $pid ) {
                print "fork : error\n" ;
        } elsif ( $pid ) {
                $children{$pid} = time ;
        } else {
                my $delay = rand( $speed ) ;
                select undef, undef, undef, $delay ;
                exit 0 ;
        }
        while ( keys %children > 20 ) { ### SEGV here??
                sleep 1 ;
        }
}

1 while wait > 0 ;
foreach my $pid ( keys %children ) {
        print "still living?? ($pid)\n" ;
}

[Please do not change anything below this line]
-----------------------------------------------------------------

---
This perlbug was built using Perl 5.00503 - Sun Mar  5 13:39:27 SAST 2000
It is being executed now by  Perl 5.008003 - Tue Apr  6 15:46:58 JST 2004.

Site configuration information for perl 5.008003:

Configured by yneko at Tue Apr  6 15:46:58 JST 2004.

Summary of my perl5 (revision 5.0 version 8 subversion 3) configuration:
  Platform:
    osname=freebsd, osvers=4.9-release, archname=i386-freebsd
    uname='freebsd lime.interlink.or.jp 4.9-release freebsd 4.9-release #0:
mon oct 27 17:51:09 gmt 2003
root@freebsd-stable.sentex.ca:usrobjusrsrcsysgeneric i386 '
    config_args='-de'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags
='-DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing',
    optimize='-O',
    cppflags='-DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing'
    ccversion='', gccversion='2.95.4 20020320 [FreeBSD]', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags ='-Wl,-E '
    libpth=/usr/lib
    libs=-lm -lcrypt -lutil -lc
    perllibs=-lm -lcrypt -lutil -lc
    libc=, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-DPIC -fPIC', lddlflags='-shared '

Locally applied patches:


---
@INC for perl 5.008003:
    /usr/local/lib/perl5/5.8.3/i386-freebsd
    /usr/local/lib/perl5/5.8.3
    /usr/local/lib/perl5/site_perl/5.8.3/i386-freebsd
    /usr/local/lib/perl5/site_perl/5.8.3
    /usr/local/lib/perl5/site_perl
    .

---
Environment for perl 5.008003:
    HOME=/root
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin
:/usr/X11R6/bin:/root/bin
    PERL_BADLANG (unset)
    SHELL=/bin/csh




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About