Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-01-2004, 06:08 PM   #1
LQ Newbie
Registered: May 2004
Posts: 13

Rep: Reputation: 0
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
Old 06-01-2004, 07:18 PM   #2
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
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'
Old 06-01-2004, 11:43 PM   #3
Registered: Feb 2003
Location: Wichita, KS
Distribution: Heavily modified Redhat
Posts: 194

Rep: Reputation: 30
Perhaps you should look into using pthread.
Old 06-02-2004, 03:04 AM   #4
Registered: Sep 2003
Location: Pune, India
Distribution: Red Hat
Posts: 106

Rep: Reputation: 15
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
GCC fork() - Can a child change a parent variable? johnhardey Programming 4 03-10-2005 10:49 AM
parent and child processes skora Programming 5 11-02-2003 10:41 AM
about parent and child process winwar Solaris / OpenSolaris 3 07-23-2003 06:07 AM
child and parent process error jdevanand Programming 1 04-29-2002 08:13 AM
child-parent-&-fork mukul Programming 2 03-24-2001 01:12 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:43 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration