Two way Pipe Process


 
Thread Tools Search this Thread
Top Forums Programming Two way Pipe Process
# 1  
Old 02-11-2010
Two way Pipe Process

Hi.. I am hoping someone could assist me with the pipe program I wrote below. I want to have communication from parent to child and then child to parent.. Is my logic right?

Code:
int p[2],p1[2];
 pipe(p);
	pipe(p1);
	pid_t pid = fork();
	
	if(pid == 0)
	{
	close(p[1]);
	close(p1[0]); 
		
	dup2(p[0],0);
	dup2(p1[1],1); 
		
	execl("program","program",0);		

	}
	else
	{ 
		
		rcvd=read (sessionSocket, & buffer, sizeof( DataChunk ) );
		close(p[0]);
		close(p1[1]);
		
if ( rcvd < 0) {
		fprintf (stderr, "\nError Reading Socket, ERROR#%d\n", errno);
		perror (progName);
		return EXIT_FAILURE;
		}
		
if ( sizeof( DataChunk ) != rcvd )
		{
		fprintf (stderr, "\nReceived incomplete packet!\n");
		return EXIT_FAILURE;
		}
	
		write(p[1],&buffer,sizeof(DataChunk));
		read(p1[0], &buffer, sizeof(DataChunk) );

}


Last edited by pludi; 02-12-2010 at 02:34 AM.. Reason: code tags, please...
# 2  
Old 02-19-2010
I guess your logic has a small problem , since you want to have a communication
between the parent and the child, please look over the block of ( pid == 0 ) ( probably a child ) and you did not put the write or read statement , I guess you put the both in the parent itself.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using pipe command between process and concatenate

Dear all, I use a pipe command to assign a variable: $ v_LstStdCdhId=$(cat Bteq_Xport_GetLstStdViewToBuild__1274.txt | grep 'CD/39/AT/CDH_BV_ODS'|cut -d"/" -f1) $ echo "${v_LstStdCdhId}" 43 49 My aim is to concatenate for each line of the variable v_LstStdCdhId the character "/" in... (3 Replies)
Discussion started by: dae
3 Replies

2. Shell Programming and Scripting

How to ignore Pipe in Pipe delimited file?

Hi guys, I need to know how i can ignore Pipe '|' if Pipe is coming as a column in Pipe delimited file for eg: file 1: xx|yy|"xyz|zzz"|zzz|12... using below awk command awk 'BEGIN {FS=OFS="|" } print $3 i would get xyz But i want as : xyz|zzz to consider as whole column... (13 Replies)
Discussion started by: rohit_shinez
13 Replies

3. Shell Programming and Scripting

Cannot make pipe for process substitution: Too many open files

Hi, I've came across an issue with a script I've been writing to check DHCP addresses on an Solaris system, the script has been running reasonably well, until it hit the following problem: ./sub_mon_v2: redirection error: cannot duplicate fd: Too many open files ./sub_mon_v2: cannot make... (3 Replies)
Discussion started by: CiCa
3 Replies

4. Programming

Communicate with multiple process using named pipe

how to read and write on pipes to communicate with each other? (5 Replies)
Discussion started by: nimesh
5 Replies

5. Shell Programming and Scripting

Replace pipe with Broken Pipe

Hi All , Is there any way to replace the pipe ( | ) with the broken pipe (0xA6) in unix (1 Reply)
Discussion started by: saj
1 Replies

6. UNIX for Dummies Questions & Answers

No process to read data written to a pipe on AIX

We use SAP application cluster on AIX. Communication between 2 of its instances is failing randomly with the following error: java.net.SocketException: There is no process to read data written to a pipe. The above error causes a cluster restart if an important communication fails. Can... (0 Replies)
Discussion started by: RoshniMehta
0 Replies

7. Shell Programming and Scripting

Can I pipe stderr to another process

Hi there, I was wondering if it was possible to pipe stderr to another process. I need to eval commands given as arguments and I would like to redirect stderr to another process. I can redirect stderr to a file like this... toto:~$ command="one=1" toto:~$ eval $command 2> error toto:~$... (5 Replies)
Discussion started by: chebarbudo
5 Replies

8. AIX

Tape drive problem - no process to read data written to a pipe

Hi Everyone, The machine I'm working on is an AIX 5.3 LPAR running on a P650. oslevel -r shows 5300-08. I'm trying to take a backup to a SCSI tape drive, which has been working up until this point. I know of nothing that has changed recently to cause this problem. But when I try to take a... (0 Replies)
Discussion started by: need2bageek
0 Replies

9. UNIX for Advanced & Expert Users

AIX 5.3 - There is no process to read data written to a pipe

I have the following code which works on AIX 4.3 but fails at times on AIX 5.3 with: cat: 0652-054 cannot write to output. There is no process to read data written to a pipe. validator="${validator_exe} ${validator_parms}" cmd_line="${CAT} ${data_file} | ${validator}... (6 Replies)
Discussion started by: vigsgb
6 Replies

10. Programming

sychronize process using pipe?

can pipe sychronize thread or process? because I'm trying to create 5 thread or process that can take an integer value and display it. each time a thread display the value, it has to be decrement it by 1 until the value has reach 0. The problem that I'm having is how can that integer value be... (1 Reply)
Discussion started by: saipkjai
1 Replies
Login or Register to Ask a Question