Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 14 Sep 1997 03:11:10 -0700
From:      Jason Thorpe <thorpej@nas.nasa.gov>
To:        Simon Shapiro <Shimon@i-connect.net>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: What is wrong with this snipet? 
Message-ID:  <199709141011.DAA01459@lestat.nas.nasa.gov>

next in thread | raw e-mail | index | archive | help
On Sat, 13 Sep 1997 16:34:42 -0700 (PDT) 
 Simon Shapiro <Shimon@i-Connect.Net> wrote:

 > Why would the following segfault on 6 of the 10 iterations?

In the FreeBSD implementation of RFMEM (which does not match Plan 9's),
the child gets the same stack as the parent.  If you "return" in the child,
someone's stack gets munched.

 > 
 > int
 > main(int argc, char **argv, char **argp)
 > {
 >     int ndx;
 > 
 >     for ( ndx = 0; ndx < 10; ndx++ ) {
 >         switch ( rfork(RFPROC|RFNOWAIT|RFFDG|RFMEM) ) {
 >         case -1:
 >             (void)fprintf(stderr, "%s ERROR: Failed to fork (%s)\n",
 >                           argv[0], strerror(errno));
 >             break;
 >         case 0:
 >             return(0);
 >         }
 >     }
 > 
 >     return(0);   
 > }
 > 
 > ---
 > 
 > 
 > Sincerely Yours,                               (Sent on 13-Sep-97, 16:31:40
 > by XF-Mail)
 > 
 > Simon Shapiro                                                Atlas Telecom
 > Senior Architect         14355 SW Allen Blvd., Suite 130 Beaverton OR 97005
 > Shimon@i-Connect.Net          Voice:  503.643.5559, Emergency: 503.799.2313

Jason R. Thorpe                                       thorpej@nas.nasa.gov
NASA Ames Research Center                            Home: +1 408 866 1912
NAS: M/S 258-6                                       Work: +1 415 604 0935
Moffett Field, CA 94035                             Pager: +1 415 428 6939



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199709141011.DAA01459>