[LCP] mapping memory

Paul Gearon gearon at ieee.org
Tue Nov 4 16:13:25 EST 2008


I should point out that shm_open and mmap are both for IPC. If you are
using threads then you don't need IPC since memory and file handles
are shared by all threads in a process. You can often make IPC more
robust ("watcher" processes can detect other processes dying and
restart them), but threads have the advantage of being able to share
memory and file handles. (that does NOT mean they don't need to
synchronize on them though)

On Mon, Nov 3, 2008 at 10:51 PM, Mark Farnell <mark.farnell at gmail.com> wrote:
> One more question:
>
> Suppose if my process calls shm_open() to create a shared-memory
> object (with O_CREAT | O_EXCL) and its threads make some mmap
> mappings, then my process crashes (i.e. no opportunity to call
> shm_unlink()).  Suppose if this object is *not* shared (or opened) by
> other processes, then will the crash of my process trigger the shared
> object to be deleted (i.e. shared memory freed).  Otherwise this would
> result in a big memory leak that can be resolved only by rebooting!

Shared memory is cleaned up after processes die... so long as there
are no remaining references. The same goes for file handles (which
shared memory is associated with).

Paul



More information about the linuxCprogramming mailing list