Shared Memory

Duane Morse duane at anasazi.UUCP
Wed Apr 24 02:05:02 AEST 1985


> 
> > > > 	How do you pass a key from one process to
> > > > another process so that both processes have acess to the
> > > > same "shmid"?

> The above article from mod.unix seems
> to be about what I'm trying to do, but I have been unable to find ANY
> references in our on-line documentation to ftok() or sdtipc...  Are they
> for 4.2BSC, or Sys V, or what? 

We had the same need and essentially invented ftok before we stumbled
across it. The basic idea is to create a file and to use the file's
inode number (with the possible addition of a identifying character)
as the key for a shared memory segment. Unix guarantees that the
inode number will be unique within a file system, so as long as all of
your shared memory "files" are on the same file system, you shouldn't
have any problem with duplicate keys. Further, since only the inode
number of the shared memory "file" is needed, the file itself can
be of 0 length, thus saving 1K that would otherwise be allocated.

The addition of an identifying character to the full key (inode numbers
are shorts, so you have another 16 bits to play with in the shared memory
key) serves two purposes. First, it may be needed to avoid conflicts with
shared memory keys that don't follow the above scheme. Second, it provides
flexibility in your naming conventions. For instance, perhaps it would
be more convenient for you to have only one shared memory "file" and
a number of different identifiers for different memory segments.

Duane Morse
International Anasazi @ Phoenix


"file" is 



More information about the Comp.unix mailing list