Thursday, May 23, 2013

A program to implement simple pipe.



Write a program to implement simple pipe.

#include<stdio.h>
#include<error.h>
#include<fcntl.h>
#define max 20
int main()
{
            int fd[2],pid;
            char l[max];
            pipe(fd);
            if((pid=fork())<0)
            {
                        printf("error");
            }
            else if(pid>0)
            {
                        close(fd[0]);
                        printf("enter the msg");
                        scanf("%s",l);
                        write(fd[1],l,12);
            }
            else
            {
                        close(fd[1]);
                        read(fd[0],l,12);
                        puts(l);
            }
}

Output:












No comments:

Post a Comment