From owner-freebsd-questions Fri Mar 24 16:40:48 2000 Delivered-To: freebsd-questions@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id D742C37B711 for ; Fri, 24 Mar 2000 16:40:44 -0800 (PST) (envelope-from bright@fw.wintelcom.net) Received: (from bright@localhost) by fw.wintelcom.net (8.10.0/8.10.0) id e2P14Ux03163; Fri, 24 Mar 2000 17:04:30 -0800 (PST) Date: Fri, 24 Mar 2000 17:04:30 -0800 From: Alfred Perlstein To: Sabrina Minshall Cc: questions@FreeBSD.ORG Subject: Re: daemon + fork Message-ID: <20000324170429.C21029@fw.wintelcom.net> References: <200003250033.QAA03821@shell.accesscom.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i In-Reply-To: <200003250033.QAA03821@shell.accesscom.com>; from sabrina@accesscom.com on Fri, Mar 24, 2000 at 04:33:03PM -0800 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG * Sabrina Minshall [000324 16:57] wrote: > > Guys, here's the problem. > > I've a daemon which waits for incoming connections on a socket. > When a connection request comes in, it allocates memory for the > request and forks a child to handle the request - passing in > the request structure the daemon allocated. Can the daemon > and the child modify the request structure at the same time? No, once you fork all your memory is COW'd (copy on write) each instance of the process will only see it's own changes. If you want to share memory you'll need to use... shared memory :) check out: man shmget man mmap Now, if you use threads then all the "children" see each other's memory, you'll want to get a book on "pthreads" and check out the pthead manpages man pthread > The child updates the request structure and then exits. How will > the parent know when the child is done? with processes you'd call "wait()" see "man 2 wait", with pthreads you'd call "pthread_join()" > If theres sample code to look at I'd appreciate a pointer. There's tons of samples, download apache, sendmail or any other network daemon that comes with source. best of luck, -- -Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org] To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message