For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > September 2005 > fork() question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author fork() question
googler

2005-09-29, 6:59 pm

Inside my C++ program, I'm creating a child process with fork(). This
child process is supposed to receive some signal after some time, when
it invokes a callback function. Now, I want this callback function to
be executed as if it is being called from the parent process (because
there are global variables which might have changed by now inside the
parent). How can this be done?

Thanks in advance.

Rich Teer

2005-09-29, 6:59 pm

On Thu, 29 Sep 2005, googler wrote:

> Inside my C++ program, I'm creating a child process with fork(). This
> child process is supposed to receive some signal after some time, when
> it invokes a callback function. Now, I want this callback function to
> be executed as if it is being called from the parent process (because
> there are global variables which might have changed by now inside the
> parent). How can this be done?


Without a huge amount of trickery, it can't be done. The two processes
are independant so a variable that is global in one won't be seen in the
other.

Now, if you were to implement this using threads, you'd be OK, because
threads execute in the space of one process.

--
Rich Teer, SCNA, SCSA, OpenSolaris CAB member

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-group.com/rich
David Schwartz

2005-09-29, 6:59 pm


"googler" <pinaki_m77@yahoo.com> wrote in message
news:1128026251.433698.172170@z14g2000cwz.googlegroups.com...

> Inside my C++ program, I'm creating a child process with fork(). This
> child process is supposed to receive some signal after some time, when
> it invokes a callback function. Now, I want this callback function to
> be executed as if it is being called from the parent process (because
> there are global variables which might have changed by now inside the
> parent). How can this be done?


You have to code the parent process so that it calls the callback
function when the child process directs it to.

DS


googler

2005-09-29, 6:59 pm


David Schwartz wrote:
> "googler" <pinaki_m77@yahoo.com> wrote in message
> news:1128026251.433698.172170@z14g2000cwz.googlegroups.com...
>
>
> You have to code the parent process so that it calls the callback
> function when the child process directs it to.
>
> DS


Yes, that's what we were thinking of doing, but not sure how I can make
the child process direct the parent to invoke the callback function.
Any ideas? Thanks!

joe@invalid.address

2005-09-29, 6:59 pm

"googler" <pinaki_m77@yahoo.com> writes:

> Inside my C++ program, I'm creating a child process with
> fork(). This child process is supposed to receive some signal after
> some time, when it invokes a callback function. Now, I want this
> callback function to be executed as if it is being called from the
> parent process (because there are global variables which might have
> changed by now inside the parent). How can this be done?


Use a pipe and have the child process signal the parent with whatever
information it needs.

Joe
--
It was impossible to get a conversation going;
everybody was talking too much.
- Yogi Berra
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com