Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Aug 1999 21:59:31 -0500
From:      Dan Nelson <dnelson@emsphone.com>
To:        notme <notme@lvdi.net>
Cc:        "freebsd-questions@freebsd.org" <freebsd-questions@FreeBSD.ORG>
Subject:   Re: question on fork()
Message-ID:  <19990813215930.A47261@dan.emsphone.com>
In-Reply-To: <37B4C1F3.EB0FBE1B@lvdi.net>; from "notme" on Fri Aug 13 18:10:11 GMT 1999
References:  <37B4C1F3.EB0FBE1B@lvdi.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990813215930.A47261>