From owner-freebsd-hackers Fri Dec 13 06:05:01 1996 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id GAA19119 for hackers-outgoing; Fri, 13 Dec 1996 06:05:01 -0800 (PST) Received: from bacall.lodgenet.com (bacall.lodgenet.com [205.138.147.242]) by freefall.freebsd.org (8.8.4/8.8.4) with SMTP id GAA19107 for ; Fri, 13 Dec 1996 06:04:56 -0800 (PST) Received: (from mail@localhost) by bacall.lodgenet.com (8.6.12/8.6.12) id IAA15311; Fri, 13 Dec 1996 08:04:06 -0600 Received: from garbo.lodgenet.com(204.124.123.250) by bacall via smap (V1.3) id sma015308; Fri Dec 13 08:03:53 1996 Received: from jake.lodgenet.com (jake.lodgenet.com [10.0.11.30]) by garbo.lodgenet.com (8.6.12/8.6.9) with ESMTP id IAA13634; Fri, 13 Dec 1996 08:04:10 -0600 Received: from jake.lodgenet.com (localhost [127.0.0.1]) by jake.lodgenet.com (8.8.3/8.6.12) with ESMTP id IAA08338; Fri, 13 Dec 1996 08:04:24 -0600 (CST) Message-Id: <199612131404.IAA08338@jake.lodgenet.com> X-Mailer: exmh version 1.6.9 8/22/96 To: "Marc G. Fournier" cc: "Eric L. Hernes" , hackers@FreeBSD.ORG Subject: Re: Multiple Buffer allocation of Shared Memory In-reply-to: Your message of "Fri, 13 Dec 1996 00:47:09 EST." Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 13 Dec 1996 08:04:23 -0600 From: "Eric L. Hernes" Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk "Marc G. Fournier" writes: > > 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... > Are these true parent/children, or server/client. It doesn't change *everything*, mostly it just throws out some of the shortcuts, like inheriting file descriptors and/or mmap'd regions. > 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?) I think there's a correspondence between the file mode and the PROT_*, specifically, if you open a file O_RDONLY, then mmap with PROT_WRITE, the mmap will fail with EACCES. > 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? > Yes, that looks ok. To update the image on disk, you'll need to use msync(). I'm not sure if there's ever a predictable implicit msync(). Certainly when memory is scarce, but that's not predicable. Possibly when munmap'ing, or at process exit. > >Marc G. Fournier scrappy@hub.org >Systems Administrator @ hub.org scrappy@freebsd.org > eric. -- erich@lodgenet.com http://rrnet.com/~erich erich@rrnet.com