Alter variable in parent from child

Alter variable in parent from child

Post by Brad Hubbar » Fri, 06 Sep 2002 11:50:42



I would like to fork() in a C++ program I'm writing and then alter an error
string in the parent from the child. How do I need to declare this string
to
be able to access/change it from both the child and the parent.

TIA,
Brad

 
 
 

Alter variable in parent from child

Post by Andreas K?h?r » Fri, 06 Sep 2002 12:29:24


Submitted by "Brad Hubbard" to comp.unix.programmer:

Quote:> I would like to fork() in a C++ program I'm writing and then alter an error
> string in the parent from the child. How do I need to declare this string
> to
> be able to access/change it from both the child and the parent.

> TIA,
> Brad

You could try to place the string in a shared memory segment (I
don't know how to), but a more resonable way would be to let the
parent change its own string depending on some message sent from
the child.

You could have a set of pipes for passing status codes (i.e.
messages) between child and parent.

If you would consider using POSIX Threads, this kind of thing
gets easier.

--
Andreas K?h?ri
--------------------------------------------------------------
Stable, secure, clean, free:  www.netbsd.org

 
 
 

Alter variable in parent from child

Post by M. Gessne » Sat, 07 Sep 2002 02:23:59




Quote:> Submitted by "Brad Hubbard" to comp.unix.programmer:
>> I would like to fork() in a C++ program I'm writing and then alter an
>> error string in the parent from the child. How do I need to declare
>> this string to
>> be able to access/change it from both the child and the parent.

>> TIA,
>> Brad

> You could try to place the string in a shared memory segment (I
> don't know how to), but a more resonable way would be to let the
> parent change its own string depending on some message sent from
> the child.

> You could have a set of pipes for passing status codes (i.e.
> messages) between child and parent.

> If you would consider using POSIX Threads, this kind of thing
> gets easier.

Sure, shared memory is a pretty straightforward way to do this.

Here's a link to a site that might be helpful to you:

http://www.piratehaven.org/~beej/guide/ipc/

This guy is pretty good.  I've found an error or two, which he accepted
without getting defensive.

I'd recommend starting with his page.

 
 
 

Alter variable in parent from child

Post by Brad Hubbar » Sat, 07 Sep 2002 08:47:09



>> You could try to place the string in a shared memory segment (I
>> don't know how to), but a more resonable way would be to let the
>> parent change its own string depending on some message sent from
>> the child.
> Sure, shared memory is a pretty straightforward way to do this.

> Here's a link to a site that might be helpful to you:

> http://www.piratehaven.org/~beej/guide/ipc/

> This guy is pretty good.  I've found an error or two, which he accepted
> without getting defensive.

> I'd recommend starting with his page.

Will do, thanks all.

Brad

 
 
 

1. How to export variables from Child to parent

Hi,

I am writing a small shall script. I want to invoke a child process by
 program &

and the program changes some of the variables.

How can I check the changes variable. I can used exit # and check the # .
If there is any other way to check the variables, please send me a note ...

Any help is greatly appreciated ......

Thanks ,

--

Shashi Peter Mara.....                             _|~-.  | Austin, TX 78750

Working at, not speaking for, IBM                    \)   |

2. Printer

3. Parent and Child process accessing global variable?

4. 2.5.56 kernel floppy driver bug

5. fork, parent, child and global variables

6. Looking for XFree86-4.0.x rpms for Redhat 6.x?

7. passing a child variable back to parent

8. KDEHelpCenter on SuSE

9. Environment Variable -- Child to parent

10. Parent / Child - parent exit problem

11. signals: stop child, parent told child died !

12. Can ksh script alter the environment of parent bash?

13. Parent wait for child to finish or kill it after 1 minute