in reply to Re: Duplicate Output with forking
in thread Duplicate Output with forking

Here's the bare bones, snip:

#!/usr/bin/perl -w $|++; use CGI qw(:standard); print header(); print h1('howdy!'), hr(); FORK: { if($pid = fork){ }elsif (defined($pid)){ print p('i am a child!') } } print h2("that's all folks");

This prints

that's all forks

before and after it prints 'i am a child!' for me

 

-justin simoni
!skazat!

Replies are listed 'Best First'.
Re: Re: Re: Duplicate Output with forking
by dws (Chancellor) on Mar 21, 2001 at 03:56 UTC
    You're getting the duplicate output because both the parent and the child process are falling through to the same print statement.

    Try having the child exit after it identifies itself. E.g.,

    print p('i am a child!'); exit(0); # don't fall through }

      That did the trick,

      my thanks to you,

       

      -justin simoni
      !skazat!