pipeline troubles

This is a discussion on pipeline troubles within the Linux Programming forums, part of the Platform Specific Boards category; Hi, I am attempting to create a program to make 3 child processes, the first child places 20 integers into ...

  1. #1
    Qui
    Qui is offline
    Registered User
    Join Date
    May 2003
    Posts
    30

    pipeline troubles

    Hi, I am attempting to create a program to make 3 child processes, the first child places 20 integers into the pipeline, the second child places another 2 integers into the pipeline and the thrid child reads all the data from the pipeline. i dunno who but thsi program has just gone totally wrong, could someone give me some advice on it please as my lectures are less that helpful.

    Code:
    #include<stdio.h>
    #include<unistd.h>
    
    int main()
    {
    	int fd[3][2],i,j;
    	char odd[54];
    	char even[59];
    	char buffer[113];
    	char buffer2[113];
    	pipe(fd);
    	if(fork() == 0)
    	{
    		if(fork() == 0)
    		{
    			if(fork() == 0)
    			{
    				i = 0;
    				j = 0;
    				while(i < 20)
    				{
    					sprintf(even,"%d",j);
    					write(fd[2][1],even,sizeof(even));
    					i = i + 1;
    					j = i + 1;
    				}
    				exit(0);
    			}
    			 i = 1;
    			 j = 1;
    			while(i < 21)
    			{
    				sprintf(odd,"%d",j);
    				write(fd[1][1],odd,sizeof(odd));
    				i = i + 1;
    				j = i + 1;
    			}
    			exit(0);
    		}
    		read(fd[2][0],buffer,sizeof(buffer));
    		printf("%s\n",buffer);
    		read(fd[1][0],buffer2,sizeof(buffer2));
    		printf("%s\n",buffer2);
    	}
    return 0;
    }
    Thanks Qui

  2. #2
    Qui
    Qui is offline
    Registered User
    Join Date
    May 2003
    Posts
    30
    solved it myself nm.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird Performance
    By khdani in forum Game Programming
    Replies: 18
    Last Post: 03-21-2008, 11:36 AM
  2. Pipeline freeze simulation
    By darklightred in forum C Programming
    Replies: 2
    Last Post: 07-24-2006, 12:57 PM
  3. MPI - linear pipeline solution for jacobi iteration
    By eclipt in forum C++ Programming
    Replies: 1
    Last Post: 05-03-2006, 06:25 AM
  4. Replies: 4
    Last Post: 01-15-2006, 05:14 AM
  5. having troubles
    By neandrake in forum C++ Programming
    Replies: 7
    Last Post: 03-07-2002, 09:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21