Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Mar 2000 17:04:30 -0800
From:      Alfred Perlstein <bright@wintelcom.net>
To:        Sabrina Minshall <sabrina@accesscom.com>
Cc:        questions@FreeBSD.ORG
Subject:   Re: daemon + fork
Message-ID:  <20000324170429.C21029@fw.wintelcom.net>
In-Reply-To: <200003250033.QAA03821@shell.accesscom.com>; from sabrina@accesscom.com on Fri, Mar 24, 2000 at 04:33:03PM -0800
References:  <200003250033.QAA03821@shell.accesscom.com>

next in thread | previous in thread | raw e-mail | index | archive | help
* Sabrina Minshall <sabrina@accesscom.com> [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




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