Re: Get variables from forked child



In comp.unix.programmer, 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?

Yes and no.

A child process' environment (internal variables, files, etc) is separate
and hidden from the parent process. Normally, the parent process cannot
access anything within the child process at all.

To permit the parent process to retrieve data from the child process, both
the child process /and/ the parent process must /share/ a communications
method. You can use pipes or sockets or files, have the child write the
results to the I/O mechanism, and have the parent read the results from the
I/O mechanism. You can also use "shared memory", have the child write the
results to a known memory location, and have the parent read the results
from the known memory location.

If not, what would be a better approach?

Thanks!

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------


.



Relevant Pages

  • Re: A tricky problem about Process.wait and popen
    ... There is a parent process and a fixed number of child processes. ... using IO.popen and then wait for any child process exits. ... it will read correspondant pipe to get result ... puts "Started" ...
    (comp.lang.ruby)
  • Re: DEFUNCT Processes
    ... When a child process dies the parent process gets notified with a signal ... The child process stays as DEFUNCT in the ... handler for SIGCHLD to IGNORE. ...
    (comp.unix.aix)
  • Re: Monitor a child process of a parent process,...
    ... how do i programmatically monitor a child process ... right when the parent process starts the child process. ... I know that i could use some sort of output redirection ...
    (microsoft.public.win32.programmer.kernel)
  • Re: WIndows process table and process image.
    ... the child process won't go away as long as the parent process is alive. ... only the child process is listed in process list without ... Please help me understand how Windows process is managed. ... Is there a zambie process in Windows as unix? ...
    (microsoft.public.win32.programmer.kernel)
  • Re: fork and pipe
    ... In summary, the pipe(2) call creates a single, unidirectional pipe, ... The parent process calls pipeto open two fds. ... the parent process calls forkto spawn a child process ... the child process inherits all open fds from the parent process, ...
    (comp.unix.programmer)