Implementation of Pipe in parallelism in c

The below program is a simple implementation of pipe in c. In this, the child thread takes the input and the parent child reads it.

Screenshots[Demo]



Code : 

#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
int main()
{
 int pfds[2];char buf[30];
  pipe(pfds);
  if(!fork())
 {
    printf("CHILD:writing to the pipe\n");
  write(pfds[1],"test",5);
  close(pfds[1]);
  printf("CHILD:exiting \n");
 }
 else
 {
  sleep(3);
  printf("PARENT : reading from pipe\n");
  read(pfds[0],buf,5);
  printf("PARENT:read %s",buf);
  close(pfds[0]);
 }
 return 0;
}

Comments

Popular posts from this blog

Non Restoring Division Algorithm Implementation in C

Bit Stuffing Code Implementation in Java

Hackerrank Modified Kaprekar Numbers Solution