Re: Get variables from forked child
- From: David Mathog <mathog@xxxxxxxxxxx>
- Date: Wed, 23 Apr 2008 09:08:04 -0700
slaskbrev1@xxxxxxxxx wrote:
Hi.
Im writing a small appliction in C under linux 2.6.24.
I use fork() to create a child process which does some computing
(based on a listening socket).
Is it somehow possible that from the parent (main method), access
variables set in the child?
As others have already pointed out, this is an IPC question and there are various methods available for doing it.
Perhaps you want to see some example code?
For message queues see my "msgqueue" program, which has a man page here:
http://saf.bio.caltech.edu/saf_manuals/msgqueue.html
For bidirectional serial communications (the parent and child write short messages to each other through sockets and both poll) see nio.c and nio.h files in the current beta release of nettee here:
http://saf.bio.caltech.edu/pub/software/linux_or_unix_tools/beta-nettee.tar.gz
The interface implemented for _this_ program using this method is described here:
http://saf.bio.caltech.edu/saf_manuals/beta_nettee_cmd.html
but you could certainly rearrange the parser to accomplish what you want. The communication need not be bidirectional - the child could certainly be configured to just send up whatever information the parent will need to know (so the child won't have to poll for input) and the parent could keep an eye out for those messages (it would still need to poll).
Both of these methods require the child to respond to the parent. If you want the parent to be able to pull data out of the child, no matter what the child is up to, you pretty much have to use shared memory.
Regards,
David Mathog
.
- References:
- Get variables from forked child
- From: slaskbrev1
- Get variables from forked child
- Prev by Date: Re: Get variables from forked child
- Next by Date: Re: TCP connect in Non Blocking Mode
- Previous by thread: Re: Get variables from forked child
- Next by thread: Re: Get variables from forked child
- Index(es):
Relevant Pages
|
|