Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with fork() in perl-5.6.1 on Solaris 2.6.1 #5701

Closed
p5pRT opened this issue Jul 3, 2002 · 5 comments
Closed

Problems with fork() in perl-5.6.1 on Solaris 2.6.1 #5701

p5pRT opened this issue Jul 3, 2002 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Jul 3, 2002

Migrated from rt.perl.org#10024 (status was 'resolved')

Searchable as RT10024$

@p5pRT
Copy link
Author

p5pRT commented Jul 3, 2002

From v600968@ss1149.lgb.cal.boeing.com

Created by eric.v.borduas@boeing.com

The script that follows, creates some strange output. Looking at the output, is appears that the value
of $i is being reset in the parent process after each fork (see STDOUT and STDERR below).

Also, if a foreach loop (e.g. foreach my $x (@​data) ) or a while with a shift operator is used,
the same problem occurs identical output.

We've tested the same program using perl 5.6 with the same results. However, run tested under linux the
problem is not encountered.

TEST SCRIPT​:

package main;

  use strict;

  my @​data =
  (
  'S000040014 5',
  'S000040020 7'
  );

  print STDERR "Parent $$\n";
  my $end = scalar(@​data);
  my $i = 0;
  for( ; $i < $end; ) {
  my $pid = fork();
  print $i, "\n";
  if ( $pid == 0 )
  {
  print STDERR "Child $i exiting\n";
  close(STDOUT);
  exit 0;
  }
  ++$i;
  }
 
__END__

STDOUT​:

0
0
1
0
1

STDERR​:

Parent 22716
Child 0 exiting
Child 1 exiting

Perl Info

Flags:
    category=core
    severity=critical

Site configuration information for perl v5.6.1:

Configured by v600968 at Wed Jul  3 13:13:04 PDT 2002.

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
  Platform:
    osname=solaris, osvers=2.6, archname=sun4-solaris
    uname='sunos ss1149 5.6 generic_105181-32 sun4u sparc sunw,ultra-enterprise '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=undef usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='gcc', ccflags ='-fno-strict-aliasing -I/usr/local/include',
    optimize='-O',
    cppflags='-fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='2.95.2 19991024 (release)', gccosandvers='solaris2.6'
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -ldl -lm -lc
    perllibs=-lsocket -lnsl -ldl -lm -lc
    libc=/lib/libc.so, so=so, useshrplib=true, libperl=libperl.so
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='  -R /opt/app/perl-5.6.1/lib/5.6.1/sun4-solaris/CORE'
    cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.6.1:
    /opt/app/perl-5.6.1/lib/5.6.1/sun4-solaris
    /opt/app/perl-5.6.1/lib/5.6.1
    /opt/app/perl-5.6.1/lib/site_perl/5.6.1/sun4-solaris
    /opt/app/perl-5.6.1/lib/site_perl/5.6.1
    /opt/app/perl-5.6.1/lib/site_perl
    .


Environment for perl v5.6.1:
    HOME=/export/home/v600968
    LANG=C
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/opt/app/emod/lib:/opt/app/dmadmin/product/3.1.2/unix/solaris:/opt/app/rogue/lib:/opt/app/oracle/product/7.3.4/lib
    LOGDIR (unset)
    PATH=/opt/app/perl-5.6.1/bin/:/usr/ccs/bin/:/usr/local/bin/:/opt/app/perl-5.6/bin/:/opt/app/omnimark.v3r1a:/opt/app/dmadmin/product/3.1/bin:/opt/app/oracle/product/7.3.4/bin:/usr/bin:/usr/ucb:/etc:.:/opt2/app/FSF/bin:/opt/app/oracle/product/7.3.4/bin:/opt/app/nedit-solaris:/opt/app/cvs/bin
    PERL_BADLANG (unset)
    SHELL=/bin/ksh


@p5pRT
Copy link
Author

p5pRT commented Jul 3, 2002

From @iabyn

On Wed, Jul 03, 2002 at 01​:54​:21PM -0700, Eric Borduas wrote​:

The script that follows, creates some strange output. Looking at the
output, is appears that the value of $i is being reset in the parent
process after each fork (see STDOUT and STDERR below).

What is more likely happening is that the buffer associated with STDOUT
is being output by by both parent and child processes, resulting in
duplicate output. From "perldoc -f fork"​:

  Beginning with v5.6.0, Perl will attempt to flush all files opened
  for output before forking the child process, but this may not be
  supported on some platforms (see the perlport manpage). To be
  safe, you may need to set `$|' ($AUTOFLUSH in English) or call the
  `autoflush()' method of `IO​::Handle' on any open handles in order
  to avoid duplicate output.

Try this and see if the problem goes away!

Dave.

Also, if a foreach loop (e.g. foreach my $x (@​data) ) or a while with a shift operator is used,
the same problem occurs identical output.

We've tested the same program using perl 5.6 with the same results. However, run tested under linux the
problem is not encountered.

TEST SCRIPT​:

package main;

use strict;

my @​data =
(
'S000040014 5',
'S000040020 7'
);

print STDERR "Parent $$\n";
my $end = scalar(@​data);
my $i = 0;
for( ; $i < $end; ) {
my $pid = fork();
print $i, "\n";
if ( $pid == 0 )
{
print STDERR "Child $i exiting\n";
close(STDOUT);
exit 0;
}
++$i;
}

__END__

STDOUT​:

0
0
1
0
1

STDERR​:

Parent 22716
Child 0 exiting
Child 1 exiting

--
"Emacs isn't a bad OS once you get used to it.
It just lacks a decent editor."

@p5pRT
Copy link
Author

p5pRT commented Apr 27, 2012

From @Hugmeir

On Wed Jul 03 07​:39​:57 2002, RT_System wrote​:

On Wed, Jul 03, 2002 at 01​:54​:21PM -0700, Eric Borduas wrote​:

The script that follows, creates some strange output. Looking at the
output, is appears that the value of $i is being reset in the parent
process after each fork (see STDOUT and STDERR below).

What is more likely happening is that the buffer associated with
STDOUT
is being output by by both parent and child processes, resulting in
duplicate output. From "perldoc -f fork"​:

   Beginning with v5\.6\.0\, Perl will attempt to flush all files

opened
for output before forking the child process, but this may not
be
supported on some platforms (see the perlport manpage). To be
safe, you may need to set `$|' ($AUTOFLUSH in English) or call
the
`autoflush()' method of `IO​::Handle' on any open handles in
order
to avoid duplicate output.

Try this and see if the problem goes away!

Dave.

Also, if a foreach loop (e.g. foreach my $x (@​data) ) or a while
with a shift operator is used,
the same problem occurs identical output.

We've tested the same program using perl 5.6 with the same results.
However, run tested under linux the
problem is not encountered.

TEST SCRIPT​:

package main;

use strict;

my @​data =
(
'S000040014 5',
'S000040020 7'
);

print STDERR "Parent $$\n";
my $end = scalar(@​data);
my $i = 0;
for( ; $i < $end; ) {
my $pid = fork();
print $i, "\n";
if ( $pid == 0 )
{
print STDERR "Child $i exiting\n";
close(STDOUT);
exit 0;
}
++$i;
}

__END__

STDOUT​:

0
0
1
0
1

STDERR​:

Parent 22716
Child 0 exiting
Child 1 exiting

Running this with and without flushing on Perls 5.8.4, 5.12.4, 5.14.2,
and blead, I get​:

hugmeir@​global​:~/perl-blead$ perl 10024.pl
Parent 12004
0
0
Child 0 exiting
1
1
Child 1 exiting
hugmeir@​global​:~/perl-blead$ perl 10024-flush.pl
Parent 12007
0
0
Child 0 exiting
1
1
Child 1 exiting

So I vote we mark this as resolved.

@p5pRT
Copy link
Author

p5pRT commented Apr 27, 2012

The RT System itself - Status changed from 'stalled' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Apr 27, 2012

@cpansprout - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant