Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

IPC USING PIPES

CODING:
#include<stdio.h>
int main()
{
int p,f[2],pid,n;
char message[50];
printf("\n IPC USING PIPES");
p=pipe(f);
if(p<0)
printf("\npipe error");
if((pid=fork())<0)
printf("{\n fork error");
if(pid>0)
{
printf("\n enter the message:");
scanf("%s",message);
write(f[1],message,30);
}
else
{
sleep(1);
close(f[1]);
n=read(f[0],message,sizeof(message));
printf("\n the message received is:");
puts(message);
}
}
Output:
[cs84076@LinuxServer ~]$ cc ipcp.c
[cs84076@LinuxServer ~]$ ./a.out

IPC USING PIPES


enter the message:hai
IPC USING PIPES
the message received is:hai

You might also like