LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 06-01-2004, 07:08 PM   #1
kamel
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, 08:18 PM   #2
infamous41md
Member
 
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-02-2004, 12:43 AM   #3
jspenguin
Member
 
Registered: Feb 2003
Location: Wichita, KS
Distribution: Heavily modified Redhat
Posts: 194

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

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


Reply


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 11:49 AM
parent and child processes skora Programming 5 11-02-2003 11:41 AM
about parent and child process winwar Solaris / OpenSolaris 3 07-23-2003 07:07 AM
child and parent process error jdevanand Programming 1 04-29-2002 09:13 AM
child-parent-&-fork mukul Programming 2 03-24-2001 02:12 PM


All times are GMT -5. The time now is 11:56 AM.

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