Thread: pipeline troubles

  1. #1
    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
    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, 10:36 AM
  2. Pipeline freeze simulation
    By darklightred in forum C Programming
    Replies: 2
    Last Post: 07-24-2006, 11:57 AM
  3. MPI - linear pipeline solution for jacobi iteration
    By eclipt in forum C++ Programming
    Replies: 1
    Last Post: 05-03-2006, 05: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