Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

mmap for IPC

113 views
Skip to first unread message

Jay Braun

unread,
May 1, 2013, 2:27:45 PM5/1/13
to
Just want to make sure: If I use mmap for inter-process communication, the processes that share the memory need not be forked from some parent process. They can be invoked independently, correct?

Thank you,
Jay

Rainer Weikusat

unread,
May 1, 2013, 3:08:54 PM5/1/13
to
If you're mmapping a 'publically accessible object', yes.

Lusotec

unread,
May 1, 2013, 4:12:19 PM5/1/13
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Yes, if the mapping is not anonymous. If the mapping is anonymous only the
process and its children can access the anonymous mapping (see MAP_ANONYMOUS
in man mmap).

On a side note, you may want to use shm_open instead of mmap directly if you
want to use shared memory for IPC between unrelated processes.

Regards.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iF4EAREIAAYFAlGBdyMACgkQGQjO2ccW76p39wD9ECaScfQ85/kN19WSTwOwFsnO
6L9Ipo+r/+NLuPGjebgA/3VyVttDfIYjVBikQ4x1oalXjMiLTva7kEXZfPy93Rrv
=0YXP
-----END PGP SIGNATURE-----

Rainer Weikusat

unread,
May 2, 2013, 9:42:44 AM5/2/13
to
Lusotec <nom...@nomail.not> writes:
> Jay Braun wrote:
>> Just want to make sure: If I use mmap for inter-process communication,
>> the processes that share the memory need not be forked from some parent
>> process. They can be invoked independently, correct?
>
> Yes, if the mapping is not anonymous. If the mapping is anonymous only the
> process and its children can access the anonymous mapping (see MAP_ANONYMOUS
> in man mmap).
>
> On a side note, you may want to use shm_open instead of mmap directly if you
> want to use shared memory for IPC between unrelated processes.

Quoting shm_open(3):

A POSIX shared memory object is in effect a handle which can
be used by unrelated processes to mmap(2) the same region of
shared memory.

Jasen Betts

unread,
May 4, 2013, 5:27:54 AM5/4/13
to
the venerable linux prgogrammer's guide has a good chapter on shared
memory with code examples http://www.tldp.org/LDP/lpg/

--
⚂⚃ 100% natural

--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---
0 new messages