-   Programming (
-   -   Getting a parent to communicate with its child -- fork() (

kamel 06-01-2004 07:08 PM

Getting a parent to communicate with its child -- fork()
After recently learning the fork() command I have run into a little issue. How can I get the parent to communicate with the child to communicate with the parent? I have read around a bit and think that I should be using clone() rather than fork() so that variables are shared. Here is my situation:

Parent is my main GUI which browses the currently downloaded XML tree while at the same time Child downloads/updates this XML tree and should report the percentage completed to parent so that parent can display the current status. To get around this problem I originally planned to make Child draw to my ncurses window directly, but then I realized: what if the user wanted to change the way it drew while to program is running? (I want a closable windows, a verbose mode, etc.)

Is clone() what I should use in this situation? I've never used clone so i'm a bit unsure of its usage -- would greatly appreciate a bit of help just to get started (i've read the man page and continue to be confused by it :P )

from the clone() man page:
"The main use of clone is to implement threads: multiple threads of con-
trol in a program that run concurrently in a shared memory space."
--Sounds like what i want

infamous41md 06-01-2004 08:18 PM

clone is not meant to be used by user applications, it is for thread libraries. u need a form of IPC, inter process communication. u could use a pipe, created by pipe() system call, or a FIFO, created by mkfifo() and opened with open(), or a message queue, created with msgget() (man 5 ipc). or shared memory. i suggest a google on 'unix ipc'

jspenguin 06-02-2004 12:43 AM

Perhaps you should look into using pthread.

Kumar 06-02-2004 04:04 AM

You can use pipe function call to communicate between parent and the child (see man 2 pipe for more info). A better solution I guess should be to create threads instead of creating processes where one thread downloads and the other thread updates the status. This looks more natural. And there won't be any problem in communication between them.

All times are GMT -5. The time now is 06:51 AM.