02-17-2012
You create the pipe after you fork. The pipe the child gets, and the pipe the parent gets, are created independently hence not the same pipe. There will be no communication between parent and child.
Create the pipe before the fork and you'll have the same pipe in both, connecting the two.
Remember that the copies are completely independent. Be very sure to close all ends of the pipe you're not using -- close the read-end in the parent, and the write-end in the child! Otherwise you may end up hanging when the child is done reading but, with a read-end left open in the parent, write() still doesn't fail.
This User Gave Thanks to Corona688 For This Post:
10 More Discussions You Might Find Interesting
1. Filesystems, Disks and Memory
Hello!
How I can increase or decrease predefined pipe buffer size?
System FreeBSD 4.9 and RedHat Linux 9.0
Thanks! (1 Reply)
Discussion started by: Jus
1 Replies
2. UNIX for Advanced & Expert Users
I'm very worried. I have an assignment that is due in 3 weeks, and also tute exercises which I can't seem to understand and work out.
Okay, the question:
The parent process will convert the command arguments into integer values using atoi() and store them into an integer array which you will... (2 Replies)
Discussion started by: scmay
2 Replies
3. Programming
hello ,
I have to write an application in which I had to implement both Socket Comminication and IPC- message queues.
and that process should run in Infinite loop as well I had to continously check and send data through both type of communications...
What should I use to implement it...
I had... (34 Replies)
Discussion started by: arunchaudhary19
34 Replies
4. Shell Programming and Scripting
Hi,
I need to awk some data from some text files, basic stuff, eg:
awk '/phrase/ {print $1,$2,$3}' file
Which will print columns 1 to 3 of all lines containing "phrase"
But what if I wanted to pipe just one of the columns to a command (in my case a date converter) as in:
awk... (4 Replies)
Discussion started by: Jonny2Vests
4 Replies
5. Programming
Hi,
Program A: uses pipe()
I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using:
* child
-> dup2(fd, STDOUT_FILENO);
-> execl("/path/PROGRAM B", "PROGRAM B", NULL);
* parent
-> char line;
-> read(fd, line, 100);
Question:... (2 Replies)
Discussion started by: vvaidyan
2 Replies
6. UNIX for Advanced & Expert Users
Hello,
I need help to replace the ................. of client.c that request the server implemented by server.c
------------------
Listing 1 - server.c
/* Inclusion des différentes librairies nécessaires */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
... (0 Replies)
Discussion started by: bounkolh
0 Replies
7. Programming
Hello people.
I'm trying to do something like a search engine.
Server runs in the background by using ./server & which has data from a textfile stored in an array.
Client then runs by using ./client
It will then prompt "Search for:"
For example, if I searched for Products called Instant... (0 Replies)
Discussion started by: andylbh
0 Replies
8. Programming
Hi, I will try to keep my post as compressed as my title was.
I am writing on pseudo code on a recursive function that I want to read from the one-above function-run and then give the result to the function-run down below until a stop is triggered. Example:
$ ls -la | grep x | sort
In my... (2 Replies)
Discussion started by: tarasque
2 Replies
9. Shell Programming and Scripting
I want to execute metasploit by two pipes to communicate with it, but I have troubles with that communication. When I run my program, I get this error: "stty: standard input: Inappropriate ioctl for device" and I don't receive the metasploit promt.
just select an exploit.
This is my code:... (2 Replies)
Discussion started by: dano88
2 Replies
10. UNIX for Beginners Questions & Answers
Hello... And thanks in advance for any help anyone can offer me on my question! I've been doing a lot of reading to try and find my answer... But I haven't had any luck
What I'm trying to understand is where a child process inherits global environment variables from? I understand the exec()... (2 Replies)
Discussion started by: bodisha
2 Replies