: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 [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to