System V shared memory and Ultrix ?
Darryl P. Wagoner
dpw at rayssd.UUCP
Fri Sep 26 01:05:38 AEST 1986
> However I'm still confused
> about a number of the facilities of shm*(). For example, what role does "key"
> play ? How do I pass the shared memory segment to non-related process ?
> Perhaps what I should do (it doesn't seem to be documented) is stick a non
> zero long in key and require that the communicating process shmget() with the
> same key. Right ?
Let me start by saying that I am no expert on shared memory. STDIPC(3C) is the
System V standard for IPC. The only routine that is currently in the stdipc
package is ftok, which when called and passed a file name and an "id", it
returns a unique key in key_t (long int) format. The key is based on the
id (8 bits) minor device name (8 bits) and the inode number (16 bits). By
different processes knowing what file name and "id" that was passed to ftok,
they can get the same key and therefore access the same shared memory. The
trick is to insure that all IPC programs adhere to this standard.
> Is the shared memory segment automatically destroyed if no process has
> it "open" ? What constitutes the "open" - the shmget() or the shmat() ? If it
> isn't destroyed then probably the shmat() is the "open" and the shmget() is
> a lookup/create.
No, once shmget is called, the shared memory identifier will remain until one
of two things happen. First shmctl is called to remove it. Second the system
is rebooted.
This is what I believe, but I could very well be wrong. The shmget call creates
an entry for the key in a shared memory table (link list I would guess).
That contains the shared memory identifier, the key, a pointer to
the shared memory and the rest of the shared memory information.
Shmat() attaches a segment to the shared memory identifier.
The question that I have is, if you call shmat with the address of a
segment in your program, will that segment dry up and blow away when you
program exited. I know the shared memory identifier will remain.
> shmflg = IPC_CREAT + 0666;
> key = IPC_PRIVATE;
key = ftok("/usr/bin/lint",'a');
/* if the file is change (as in remove then recreated) it will change
the key that is returned */
Damn it Jim, I am a programmer, not a Englist Major
Darryl Wagoner
Raytheon Co.; Portsmouth RI; (401)-847-8000 x4089
best path {allegra|gatech|mirror|raybed2} ---------\
next best {linus|ihnp4|pyrbos} ---------------------->!rayssd!dpw
if all else fails {brunix|cci632} -------------------------/
--
Darryl Wagoner
Raytheon Co.; Portsmouth RI; (401)-847-8000 x4089
best path {allegra|gatech|mirror|raybed2} ---------\
next best {linus|ihnp4|pyrbos} ---------------------->!rayssd!dpw
if all else fails {brunix|cci632} -------------------------/
More information about the Comp.unix.wizards
mailing list