Re: Is shmdt() necessary?



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.

.



Relevant Pages

  • Re: Is shmdt() necessary?
    ... memory by calling shmat, and will detach from it before it exits, by ... one process will destroy the shared memory and this ... Some people find it more elegant to explicitly detach everything they ... if there's only a limited amout of shared memory segments at ...
    (comp.os.linux.development.system)
  • Re: Is shmdt() necessary?
    ... memory by calling shmat(), and will detach from it before it exits, by ... attach number if one process ends without calling shmdt. ... Some people find it more elegant to explicitly detach everything they ...
    (comp.os.linux.development.system)
  • Re: Is shmdt() necessary?
    ... memory by calling shmat, and will detach from it before it exits, by ... one process will destroy the shared memory and this ... if there's only a limited amout of shared memory segments at ...
    (comp.os.linux.development.system)
  • Re: Non contiguous Virtual Memory
    ... >> There is no need to attach or detach from the shared memory. ... >> rights. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Non contiguous Virtual Memory
    ... > There is no need to attach or detach from the shared memory. ... > You will just slide the view over the same section. ... Windows shared memory concept so excuse me if I am asking any silly question ...
    (microsoft.public.win32.programmer.kernel)

Loading