UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2007-01-17 04:14 PM

yurec
Member
From: Singapore
Registered: 2006-11-16
Posts: 134

Re: shm_unlink

"Even if the object continues to exist after the last shm_unlink(),  reuse  of  the  name  shall  subsequently  cause shm_open()  to behave as if no shared memory object of this name exists (that is, shm_open() will fail if O_CREAT is not set, or will create a new shared memory object if O_CREAT is set)." linux manual

In a class I call shm_open with O_RDWR | O_CREAT|O_EXCL flag and if returns -1 and errno is EEXIST I change flag to O_RDWR and call shp_open again.In a destructor I call shm_unlink.First time the class created all is ok,but after destructing on new call shm_open with O_RDWR | O_CREAT|O_EXCL flag I do not get error(so as manual says).So how do I know the memory is created and I don't need O_CREAT flag?I want my class to create or attach memory automatically by the name given in the parametr of a constructor.

Offline

#2 2007-01-17 04:37 PM

yurec
Member
From: Singapore
Registered: 2006-11-16
Posts: 134

Re: shm_unlink

I must call shm_unlink for each call of shm_open?

Offline

#3 2007-01-17 08:28 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,847
Website

Re: shm_unlink

I don't mess around with the shm_*() stuff much, but just by analogy with regular
files and open()/unlink(), I think you only want to be calling shm_unlink() if you
were the one who actually created the thing in the first place...  Or, if you know
that no future processes should continue to open the existing shared memory
object...  When you shm_unlink() it, it's going to go away at least in name, in the
same manner that a file goes away when you unlink() it: it's no longer accessable
to anyone via that name, but anyone holding open FDs to it can still use them just
fine, and when all those FDs are closed, then it truly ceases to exist...  So, if you
want future apps to be able to access the same patch of shared memory you've
been using, then you DON'T want to unlink it; if you want them to use a new one,
you DO want to unlink it...

Offline

Board footer

Powered by FluxBB