Re: fork question
- From: "David Schwartz" <davids@xxxxxxxxxxxxx>
- Date: Sun, 22 Jan 2006 13:13:02 -0800
"Eric" <nospam@xxxxxxxxx> wrote in message
news:EeKdnbFBwIw0aU7enZ2dnUVZ_tOdnZ2d@xxxxxxxxxxxxxx
> if i use fork in my userland app, how do share a global variables between
> the parent and all the children? I need to have this variable created such
> that if anyone (parent or child) changes it all the other children and the
> parent can see the change. My only idea is a mmap'd space, I could let
> each
> process mmap the same space and use it for various shared variables, kind
> of like this:
> parent: create typedef of layout of mapped space
> parent: sp=mmap new shared space based on size of layout
> parent: sp->var1 = value
> parent: sp->var2 = value
> child1: sp=mmap existing shared space
> child1: sp->var1 = value
> child1: if(sp->var2 == value)...
> child2: sp=mmap existing shared space
> child2: sp->var1 = value
> child2: if(sp->var2 == value)...
> Is there another better way?
Have the parent create a shared memory area before it 'fork's. However,
you seem to be missing the important detail that if two processes are going
to share a memory area, they must synchronize their accesses to it (or use
atomic operations).
DS
.
- Follow-Ups:
- Re: fork question
- From: Eric
- Re: fork question
- References:
- fork question
- From: Eric
- fork question
- Prev by Date: fork question
- Next by Date: Re: fork question
- Previous by thread: fork question
- Next by thread: Re: fork question
- Index(es):
Relevant Pages
|