LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 05-01-2007, 11:14 AM   #1
sudif
LQ Newbie
 
Registered: Sep 2005
Posts: 11

Rep: Reputation: 0
fork() // parent & child communication


i need to write a program that receives data from the child process and execute on it in the parent then the parent waits for the child to send the data again.

can i do it using fork wait and pipe and how???
 
Old 05-01-2007, 11:27 AM   #2
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
I believe the short answer is: yes you can communicate between the parent and child process using a pipe.

The long answer is: I don't know how to do it off the top of my head. Spend some time googling and I'm sure you'll find it. I found it via Google when I was researching how to do it.

HTH
 
Old 05-01-2007, 12:05 PM   #3
sudif
LQ Newbie
 
Registered: Sep 2005
Posts: 11

Original Poster
Rep: Reputation: 0
couldn't find exactly what i need
 
Old 05-01-2007, 12:15 PM   #4
Whyte
LQ Newbie
 
Registered: Mar 2007
Distribution: Ubuntu
Posts: 17

Rep: Reputation: 4
Code:
int p[2];
pipe(p); // also check if it returns <0 (error)
// p[0] should now be open for reading
// p[1] for writing
Then do a fork(), and (you MUST) close() the Read descriptor in one process, and the Write descriptor in the other process. Then, whatever you write() into p[1], you will read from p[0].

man 2 pipe for details. man 3 mkfifo for another approach.
 
Old 05-01-2007, 01:30 PM   #5
Kristofer
LQ Newbie
 
Registered: Nov 2005
Location: Sweden
Distribution: Slackware
Posts: 20

Rep: Reputation: 0
Beejs IPC guide

http://www.ecst.csuchico.edu/~beej/guide/ipc/pipes.html

Take a look at "fork() and pipe()--you have the power!"

/Kristofer
 
Old 05-02-2007, 03:11 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
you should explain precisely what you are trying to do, not how you want it done.
 
  


Reply



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
Getting a parent to communicate with its child -- fork() kamel Programming 3 06-02-2004 03:04 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-parent-&-fork mukul Programming 2 03-24-2001 01:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:36 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
Open Source Consulting | Domain Registration