Date: Wed, 04 Feb 1998 08:50:05 +0100 From: Michael Schuster <Michael.Schuster@utimaco.co.at> To: "hackers@FreeBSD.ORG" <hackers@FreeBSD.ORG> Subject: Re: Shared memory and signals Message-ID: <34D81DAD.F3B30021@utimaco.co.at> References: <199802040717.RAA07706@cain.gsoft.com.au>
next in thread | previous in thread | raw e-mail | index | archive | help
Daniel O'Connor wrote:
> Hmm, yes but I know of at least one program (paradise netrek :) which uses the
> fact that the shared mem segment is persistent...
Shared memory is persistent in the sense that you can do something like
typedef struct {
int magic;
....
} my_struct;
void *mem;
int size = sizeof (my_struct);
key_t key = MY_KEY; /* some constant key */
fd = shmget (key, size, ...);
mem = shmat (fd, ...);
if (((my_struct *) mem)->magic == MY_MAGIC) { /* re-attached */
/* re-use memory .... */
} else {
/* do what you have to do with newly attached mem */
((my_struct *) mem)->magic = MY_MAGIC;
}
/* ..... */
shmdt (mem);
as often as you like, and you (and any other process) will always get
the same memory segment (although the pointers may not be the same -
they're virual addresses, of course) with the contents you left in there
the last time you used it (provided noone has changed it, of course).
Once you IPC_RM it even once though, it's gone (in fact you can only
IPC_RM it once; subsequent IPC_RMs will give you an invalid argument
error) and lost immediately for all and any process.
--
Michael Schuster
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?34D81DAD.F3B30021>
