AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
 View Only

Using mmap to set up shared memory, then later mapping to non-shared

  • 1.  Using mmap to set up shared memory, then later mapping to non-shared

    Posted Wed October 21, 2009 04:49 PM

    Originally posted by: jpiaget


    I am using mmap() to set up shared memory for an application which forks multiple processes. After these processes exit, I would like to set the shared memory regions which have been used to non-shared.

    The initial mmap
    int fd = open("/dev/zero", O_RDWR)
    origMem = (void **)mmap(0,0x80000000,PROT_READ|PROT_WRITE,MAP_SHARED, fd, 0);

    ... later
    newMem = (void **)mmap(origMem, 0x80000000,PROT_READ|PROT_WRITE,MAP_FIXED|MAP_PRIVATE,fd,0)
    // newMem should be == origMem

    The second mmap fails, although I think this should be OK based on the documentation I have seen.

    Thanks
    #AIX-Forum