From owner-freebsd-hackers Thu Dec 12 21:47:27 1996 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id VAA20414 for hackers-outgoing; Thu, 12 Dec 1996 21:47:27 -0800 (PST) Received: from hub.org (root@hub.org [207.107.138.200]) by freefall.freebsd.org (8.8.4/8.8.4) with ESMTP id VAA20408 for ; Thu, 12 Dec 1996 21:47:24 -0800 (PST) Received: from localhost (scrappy@localhost) by hub.org (8.8.2/8.7.5) with SMTP id AAA18275; Fri, 13 Dec 1996 00:47:11 -0500 (EST) Date: Fri, 13 Dec 1996 00:47:09 -0500 (EST) From: "Marc G. Fournier" To: "Eric L. Hernes" cc: hackers@FreeBSD.ORG Subject: Re: Multiple Buffer allocation of Shared Memory In-Reply-To: <199612101935.NAA16873@jake.lodgenet.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk 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, , 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, , 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