From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <60c7fdf45121206846fb9f34f2588b77@collyer.net> To: 9fans@cse.psu.edu Subject: Re: [9fans] shared memory From: Geoff Collyer In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Fri, 12 Sep 2003 02:25:48 -0700 Topicbox-Message-UUID: 3217adac-eacc-11e9-9e20-41e7f4b1d025 I wouldn't have called shmat `user friendly' and I don't think it's any easier to use than the Plan 9 machinery. shmat, shmget, etc. don't really do much for you; they just do what segattach does, but in a more complicated way. You still have to arrange to coordinate access by the processes sharing the memory. I think char *ss = (char *)segattach(0, "shared", nil, length); is all you need to allocate a shared segment of size `length', though you still have to actually share it, probably by forking. If the processes in question are related, you don't even need segattach, just be careful to keep per-process data on the stack (in automatic variables) and when you rfork(), be sure to include the RFMEM flag. After the rfork, parent and child will share their data segment. If you're looking for a way for unrelated processes to share memory, I think your best bet is to use the undocumented S option of ramfs: ramfs -S shared1 to create a sharable /tmp, then have all the programs that want to share the memory do: mkdir /tmp/shared1 mount -c /srv/shared1 /tmp/shared1 The 'l' permission bit on files in /tmp/shared1 can implement locks. How are you trying to share memory (or what are you trying to accomplish)? All of the above assumes that you want something like System V shared memory.