Getting parent/child shared memory using mmap()

Getting parent/child shared memory using mmap()

Post by Ilya Klebano » Wed, 19 Jan 2000 04:00:00



Dear all,

I was trying to implement some code samples found in R.Stevens's bible. I
need some memory shared between parent and a child, and was hoping to get
away with mmap(), using either MAP_ANON flag or using open file handle
/dev/zero.

There is a piece of code ( I'm omitting any error control):
{
    int file;
    caddr_t pvAllocation;

    file = open( "/dev/zero",
                      O_RDWR);

    pvAllocation = mmap(  0,
                                        cbAllocationSize,
                                        PROT_READ | PROT_WRITE,
                                        MAP_SHARED,
                                        file,
                                        0);

    pvAllocation = mmap(  0,
                                        cbAllocationSize,
                                        PROT_READ | PROT_WRITE,
                                        MAP_SHARED | MAP_ANON,
                                        -1,
                                        0);

    close( file);

Quote:}

In both cases pvAllocation is returned as -1, and errno is set no EINVAL
 0x16).
file gets a valid descriptor number.

Any help will be highly appreciated.

Thank you,
Ilya

 
 
 

1. Shared memory problrm between parent and child processes

Hi, there

I want to use shared memory to share data between parent process and the
child process it forks. I understand that the child just copy the data
segment from parent, but not pointing to the same place. I tried shm**
and sem** operations. But it dose not work as I expected. Semaphores are
in different processes. E.g. parent can do P on its semaphore, but child
can not do V on that semaphore. I know that I might make some mistake
or not quite understand the usage. Could anyone give some idea?

BTW, I am on solaris 2.5.1, which dose not support sem_init, sem_open,
etc, yet.

Regards

--
Ruibiao
(Qiu, Ruibiao)
-------------------------------------------------------------------
Telephone:            |  Email:

(O)(305)248-3740      |  Home Page:
(H)(305)220-9294      |  http://www.cs.fiu.edu/~rqiu01
-------------------------------------------------------------------

2. looking for shell account

3. sharing memory between parent/children

4. Cannot resolve name to ip address

5. Shared memory between Parent/Child process?

6. Xlib: connection to ":0.0" refused by server

7. Memory used by parent/child

8. Setting up a PPP server for FreeBSD

9. can a child munmap without destroying the parents mmap?

10. Trying to get shared memory using mmap?

11. Shared Memory using mmap

12. Getting children's PID with parent's pid?

13. Parent process getting child's environment?