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

Ipc - Pipes

This C program demonstrates interprocess communication using pipes. The parent process prompts the user to enter a number, writes that number to a pipe, and the child process reads from the pipe and prints whether the number is even or odd. The parent and child processes exchange information through the pipe to communicate the number and the result.

Uploaded by

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

Ipc - Pipes

This C program demonstrates interprocess communication using pipes. The parent process prompts the user to enter a number, writes that number to a pipe, and the child process reads from the pipe and prints whether the number is even or odd. The parent and child processes exchange information through the pipe to communicate the number and the result.

Uploaded by

PavithraRam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

K.

APARNA
412512104009
INTERPROCESS COMMUNICATION USING PIPES
#include<stdio.h>
main()
{
Intpid,ppid,pdes[2],n,a;
Printf(\n IPC using pipes);
if(pipe(pdes==-1)
{
printf(\n No error);
exit(1);
}
else
{
pid=fork();
if(pid==-1)
printf(\nThe Error is in progress);
else
if(pid)
{
close(pdes[0]);
printf(\n Process id %d,getppid());
printf(\n Process id %d,getpid());
printf(\n Enter the number of processes:);
scanf(%d,&a);
write(pdes[1],&a,sizeof(a));
}
else
{
close(pdes[1]);
open(pdes[0]);
read(pdes[0],&n,sizeof(n));
if(n%2==0)
printf(\n Number %d is even,n);
else
printf(\n Number %d is odd,n);
}} }
OUTPUT:
[cse2a@sys-do8~] $ vipipe.c
[cse2a@sys-do8~] $ cc pipe.c
[cse2a@sys-do8~] $ ./a.out
IPC using pipes
Process id 7383
Process id 13229
Number of processes:6
IPC using pipes
Number 6 is even

You might also like