From owner-freebsd-questions Fri Aug 13 20: 0:20 1999 Delivered-To: freebsd-questions@freebsd.org Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by hub.freebsd.org (Postfix) with ESMTP id A777414D0C for ; Fri, 13 Aug 1999 20:00:18 -0700 (PDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.9.3/8.9.3) id VAA47431; Fri, 13 Aug 1999 21:59:31 -0500 (CDT) (envelope-from dan) Date: Fri, 13 Aug 1999 21:59:31 -0500 From: Dan Nelson To: notme Cc: "freebsd-questions@freebsd.org" Subject: Re: question on fork() Message-ID: <19990813215930.A47261@dan.emsphone.com> References: <37B4C1F3.EB0FBE1B@lvdi.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.95.6i In-Reply-To: <37B4C1F3.EB0FBE1B@lvdi.net>; from "notme" on Fri Aug 13 18:10:11 GMT 1999 X-OS: FreeBSD 4.0-CURRENT Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In the last episode (Aug 13), notme said: > When using the funciton fork(), in a c program if the child process > happen to interact with a user, and it happens that more than one > user (all using different child process) access one piece of data > (i.e, say it is a binary tree) and modifying it, will the piece of > data get update simultanously? (i.e, say both users are adding a > node, seperately to this tree, will this tree have 2 nodes added to > it?) Or is it even possible to do so? When you fork(), the child essentially gets its own copy of any memory allocated by the parent. If either the parent of child modifies a piece of memory, the modification is not seen by any other process. The exceptions to this are mmap()ed areas and SysV shared memory; you can allocate memory via mmap() with the flags MAP_ANON|MAP_SHARED which lets all children see changes made by other children/parent. SysV SHM is similar except that the memory is semi-permanent (stays around after all users exit) and independant processes can attach/detach the segment without necessarily having a common parent. -- Dan Nelson dnelson@emsphone.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message