Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

[perl #10024] Problems with fork() in perl-5.6.1 on Solaris 2.6.1

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


perlbug-followup at perl

Apr 27, 2012, 6:25 AM

Post #1 of 1 (63 views)
Permalink
[perl #10024] Problems with fork() in perl-5.6.1 on Solaris 2.6.1

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 [at] globa:~/perl-blead$ perl 10024.pl
Parent 12004
0
0
Child 0 exiting
1
1
Child 1 exiting
hugmeir [at] globa:~/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.


---
via perlbug: queue: perl5 status: stalled
https://rt.perl.org:443/rt3/Ticket/Display.html?id=10024

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.