[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: programming: fork() related question



Yes.
Shared memory regions are shared across parent and children:

man shmget, shmat, shmctl 

Shared memory is pretty simple, and very convenient.

Alternatively mmap()ing a file and using that works too, and has the
advantage of reboot-lasting persistence.

I believe The Great Richard Stevens's (RIP) book has some good
examples, but both memory mapped files and shared memory are pretty
easy.


Dom
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dom De Vitto                                       Tel. 07855 805 271
http://www.devitto.com                         mailto:dom_(_at_)_devitto_(_dot_)_com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-----Original Message-----
From: owner-misc_(_at_)_openbsd_(_dot_)_org [mailto:owner-misc_(_at_)_openbsd_(_dot_)_org] On Behalf Of
Sacha Ligthert
Sent: Saturday, December 13, 2003 6:54 PM
To: misc_(_at_)_openbsd_(_dot_)_org
Subject: programming: fork() related question

Hi Misc@

Maybe this should've gone to comp.programming, since its activity has been
pretty low the last couple of months I'll take my chances here.

Is there a way to have the same values in the parent and a child of a
fork().

For example:
int   a;
a=0;
if (!fork())
{ /*Child*/ } else { /*Parent*/ }

If I where to edit value "a" in the parent, how could I get the same value
of "a" in the child?

Any pointers, hints and/or tips are very welcome :-)

One of my pieces code can be found @
http://teksec.homeunix.net/~outcast/txt/pointerfun.c
This failed for obvious reasons..

Greetings,

Sacha



Visit your host, monkey.org