From owner-freebsd-hackers Mon Jul 17 8:55:46 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from earth.backplane.com (backplane-inc.SanFranciscosfd.cw.net [206.24.214.242]) by hub.freebsd.org (Postfix) with ESMTP id 5410E37B9CE for ; Mon, 17 Jul 2000 08:52:24 -0700 (PDT) (envelope-from dillon@earth.backplane.com) Received: (from dillon@localhost) by earth.backplane.com (8.9.3/8.9.3) id IAA93920; Mon, 17 Jul 2000 08:52:19 -0700 (PDT) (envelope-from dillon) Date: Mon, 17 Jul 2000 08:52:19 -0700 (PDT) From: Matt Dillon Message-Id: <200007171552.IAA93920@earth.backplane.com> To: "Nigel Roles" Cc: Subject: Re: rfork(RFMEM) behaviour References: Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG :I am getting strange behaviour with rfork(RFMEM) on a ~2 week old :kernel. The following code illustrates it. For all the world, the :stack appears to be shareable after the fork. This is clearly wrong, :since pid was at some point different in parent and child for them :to take the right case. : :I'm sure this is down to my stupidity. I'd be grateful for any :feedback. : :Also, I understand that rfork(RFMEM) was not supported in 3.3 under :SMP. My reading of the kernel source suggests that there is no longer :such a limitation. At which version did this change? : :Thanks, : :Nigel Roles You can't call rfork(RFPROC|RFMEM) from C, because the child process returns on the same stack. RFMEM means, literally, that the entire address space is shared... that, in fact, the *page table* itself is actually 100% shared. Under 3.x SMP this does not work because page table sharing is not possible between cpu's under 3.x. Under 3.x UP there isn't a problem. Under 4.x there is no problem (UP or SMP). -Matt : :--------------------------------------- : : :#include :#include : :int child_has_run; : :int :main(int argc, char **argv) :{ : int pid; : int value = 3; : pid = rfork(RFPROC | RFMEM); : switch (pid) { : case 0: : pid = -1; : printf("child has run\n"); : fflush(0); : child_has_run = 1; : exit(0); : case -1: : printf("rfork failed\n"); : exit(1); : default: : while (!child_has_run) : ; : printf("parent pid = %d\n", pid); : } : exit(1); :} To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message