Re: Is shmdt() necessary?
- From: Nate Eldredge <nate@xxxxxxxxxx>
- Date: Sun, 01 Feb 2009 10:03:01 -0800
Tristan <sooqing@xxxxxxxxx> writes:
Hi,
When using shared memory, one process usually attaches to the shared
memory by calling shmat(), and will detach from it before it exits, by
calling shmdt().
However, I found os(I'm using Linux 2.6.10) can also decrease the
attach number if one process ends without calling shmdt().
In my program, one process will destroy the shared memory and this
process is always running.
I just call shmat() in the process and do nothing when the process
exits. Seems it can work smoothly.
But, does this have any side-effect/potential error?
No, the Single Unix Specification guarantees this behavior. See
http://opengroup.org/onlinepubs/007908799/xsh/_exit.html, the 8th bullet
point.
Some people find it more elegant to explicitly detach everything they
attach. Also, if you used a large number of shared memory segments
sequentially, you might have to detach them in order to free up
resources before you can attach some more. But if you only have a
couple, then I see no problem with letting them be detached
automatically on exit.
.
- Follow-Ups:
- Re: Is shmdt() necessary?
- From: Tristan
- Re: Is shmdt() necessary?
- References:
- Is shmdt() necessary?
- From: Tristan
- Is shmdt() necessary?
- Prev by Date: Is shmdt() necessary?
- Next by Date: Re: Is shmdt() necessary?
- Previous by thread: Is shmdt() necessary?
- Next by thread: Re: Is shmdt() necessary?
- Index(es):
Relevant Pages
|
Loading