0% found this document useful (0 votes)
4 views1 page

IPC with Pipes in C Program

This document contains a program for inter-process communication using pipes in C. The program creates a pipe, forks a child process, writes "HelloWorld" to the pipe from the parent process, and has the child process read and print the message from the pipe. When run, the program outputs "HelloWorld" as expected, demonstrating successful communication between the parent and child processes via the pipe.

Uploaded by

Harsha patil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

IPC with Pipes in C Program

This document contains a program for inter-process communication using pipes in C. The program creates a pipe, forks a child process, writes "HelloWorld" to the pipe from the parent process, and has the child process read and print the message from the pipe. When run, the program outputs "HelloWorld" as expected, demonstrating successful communication between the parent and child processes via the pipe.

Uploaded by

Harsha patil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Name: Kanchan Kundan Chaudhari Date:-

Roll No. : 01

Subject: - Advance Unix Programming Sub. Teacher: Ashfaque Shaikh

/* Program for Inter Process Communication using pipe */


#include<stdio.h>
#include<unistd.h>
int main()
{
int n,fd[2];
pid_t pid;
char line[20];
if(pipe(fd)<0)
printf("\n error in pipe");
if((pid=fork())<0)
printf("\n error in fork");
else if(pid>0)
{
write(fd[1]," HelloWorld\n",12);
}
else
{
n=read(fd[0],line,12);
printf("%s",line);
}
return 0;
}

Output:
linux5@linux5-System-Product-Name:~/Desktop$ cc pipe.c
linux5@linux5-System-Product-Name:~/Desktop$ ./[Link]
HelloWorld

You might also like