develooper Front page | perl.perl5.porters | Postings from May 2003

[perl #22162] leak in POSIX waitpid()

From:
Sam Schinke
Date:
May 9, 2003 06:50
Subject:
[perl #22162] leak in POSIX waitpid()
Message ID:
rt-22162-57010.3.80407954081377@bugs6.perl.org
# New Ticket Created by  Sam Schinke 
# Please include the string:  [perl #22162]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=22162 >


Perlbug  wasn't sending succesfully, so I took the saved report and am
sending it manually.

This is a bug report for perl from sschinke@myrealbox.com,
generated with the help of perlbug 1.34 running under perl v5.8.0.


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

The following, saved as a .pl file produces a leak when the fork/reap
cycle is allowed to repeat several times (press enter once to fork
and then reap a new child process). Just watch perl.exe's memory use
with any process monitor. It climbs by 32k every fork or two, by my
testing.

===============================
# perl fork leak tester

use POSIX ":sys_wait_h";

my $pid = 0;

while (1) {
    
    if ( waitpid( $pid, 0 ) == $pid) {
        print "reaped, yeah!\n";
    }  
    print "Hit enter to fork and reap.\n";
    if (<>) {
        $pid = fork();
        if ($pid == 0) {
            #CHILD
            select(undef, undef, undef, 0.05);
            print "child forked, reap me baby!\n";
            exit(0);
        } else {
            print "parent still alive, oh yeah!\n";
        }
    }
    select(undef, undef, undef, 0.5);
}
================================

However, the following program does NOT leak. The memory use only
climbs on the first few forks and very quickly stabilizes.

================================
# perl fork leak tester

my $pid = 0;

while (1) {
    
    if ( waitpid( $pid, 0 ) == $pid) {
        print "reaped, yeah!\n";
    }  
    print "Hit enter to fork and reap.\n";
    if (<>) {
        $pid = fork();
        if ($pid == 0) {
            #CHILD
            select(undef, undef, undef, 0.05);
            print "child forked, reap me baby!\n";
            exit(0);
        } else {
            print "parent still alive, oh yeah!\n";
        }
    }
    select(undef, undef, undef, 0.5);
}

================================

The only difference is the removal of 'use POSIX ":sys_wait_h";'
in the second program.

Reporting this as directed in the perl-win32-users list. Please
advise if there is any additional information required.



[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=library
    severity=high
---
Site configuration information for perl v5.8.0:

Configured by ActiveState at Mon Mar 31 00:45:28 2003.

Summary of my perl5 (revision 5 version 8 subversion 0) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -Gf -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT  -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
    optimize='-MD -Zi -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -release  -libpath:"D:\Perl\lib\CORE"  -machine:x86'
    libpth="D:\Perl\lib\CORE"
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
    gnulibc_version='undef'
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release  -libpath:"D:\Perl\lib\CORE"  -machine:x86'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY

---
@INC for perl v5.8.0:
    D:/Perl/lib
    D:/Perl/site/lib
    .

---
Environment for perl v5.8.0:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=D:\PERL\BIN;C:\WINDOWS\;C:\WINDOWS;C:\WINDOWS;C:\WINDOWS\COMMAND;C:\PERL\BIN;D:\CYGWIN\BIN\;C:\WINDOWS\;D:\PROGRA~1\GRISOFT\AVG6;C:\SSL;D:\PROGRA~1\NETWOR~1\PGP
    PERL_BADLANG (unset)
    SHELL (unset)





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