Date: Fri, 13 Dec 1996 00:47:09 -0500 (EST) From: "Marc G. Fournier" <scrappy@hub.org> To: "Eric L. Hernes" <erich@lodgenet.com> Cc: hackers@FreeBSD.ORG Subject: Re: Multiple Buffer allocation of Shared Memory Message-ID: <Pine.NEB.3.95.961213002725.14115D-100000@hub.org> In-Reply-To: <199612101935.NAA16873@jake.lodgenet.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 10 Dec 1996, Eric L. Hernes wrote: > "Marc G. Fournier" writes: > > > > Okay...maybe I'm missing something as far as mmap() is concerned, > >but what I want to be able to do is allocated X bytes of memory to be > >shared amongst several processes. After the memory is allocated, I will > >*then* want to fill the memory (ie. with data read from a socket). > > > > From reading the mmap() man page (any good reference/textbooks that > >I might want to pick up?), mmap() allocates and fills the memory space at > >the same time, based on a previously opened, already existing, file (fd). > > > > Yup, > * The Design and Implemenatation of the 4.4BSD Operating System > ~page 139 > * UNIX Internals The New Frontiers > ~page 440 > > One way, is to open a (previously agreed upon) named file that > will be used to share data, ftruncate() it to the size you want, > then mmap() it. Other processes can open and mmap() this same file > to get at the data. Okay...I'm convinced that mmap() is the way to go (alot of it has to do with the fact that I'm still unable to get past 29 shm buffers *sigh*) but the more that I think on it, and re-read what has been said on the subject, the better mmap() seems...so... I picked up "Advanced Programming in the Unix Environment" by Stevens, which has several sections/examples of using mmap(), along with alot of stuff that I probably never even knew about *grin* My new "light reading", I guess... The one question that I can't seem to find addressed though is opening the named file. Now, since I'm closing the file after MMAP'ng it, does it matter how I open it? I incorrectly used the terms 'child/parent' when I first asked...the reason I'm going named file is because its a client/server environment...sorry if that changes everything, but from what I've read, I don't think it does... Now, if I understand it correctly, what I'm goin to want to do is: parent: open named file (O_RDONLY, O_RDWR, or it doesn't matter?) ftruncate named file mmap it using something similar to: mmap(0, <size of file>, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); close named file child: open named file (again, does the mode matter?) mmap it using something similar to: mmap(0, <size of file>, PROT_READ, MAP_SHARED, fd, 0); close named file Is that the gist of it? Then I can "read/write" the mmap'd area just like I would a similarly malloc()'d area, correct? Marc G. Fournier scrappy@hub.org Systems Administrator @ hub.org scrappy@freebsd.org
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.NEB.3.95.961213002725.14115D-100000>