Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Jul 2000 08:52:19 -0700 (PDT)
From:      Matt Dillon <dillon@earth.backplane.com>
To:        "Nigel Roles" <ngr@9fs.org>
Cc:        <freebsd-hackers@FreeBSD.ORG>
Subject:   Re: rfork(RFMEM) behaviour
Message-ID:  <200007171552.IAA93920@earth.backplane.com>
References:   <DAENIBHPCGABMPCKEANMIEPMCCAA.ngr@9fs.org>

next in thread | previous in thread | raw e-mail | index | archive | help
: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 <stdio.h>
:#include <unistd.h>
:
: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




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