0% found this document useful (0 votes)
2 views2 pages

5A Interprocess Communication Using Pipes Program:: Sprno:9223

The document presents a C program that demonstrates interprocess communication using pipes. It creates a pipe, forks a process, and allows the parent to send a message to the child process through the pipe. The child process then reads and prints the received message.

Uploaded by

jayaprakash9223
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)
2 views2 pages

5A Interprocess Communication Using Pipes Program:: Sprno:9223

The document presents a C program that demonstrates interprocess communication using pipes. It creates a pipe, forks a process, and allows the parent to send a message to the child process through the pipe. The child process then reads and prints the received message.

Uploaded by

jayaprakash9223
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/ 2

Sprno:9223

5A INTERPROCESS COMMUNICATION USING PIPES


PROGRAM:
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main()
{
int fd[2]; // fd[0] - read, fd[1] - write
pid_t pid;
char write_msg[] = "Hello from parent to child via pipe!";
char read_msg[100];
if (pipe(fd) == -1)
{
perror("Pipe failed");
return 1;
}
pid = fork();
if (pid < 0)
{
perror("Fork failed");
return 1;
}
if (pid > 0)
{
close(fd[0]);
write(fd[1], write_msg, strlen(write_msg) + 1);
close(fd[1]);
}
else
{
Sprno:9223

close(fd[1]);
read(fd[0], read_msg, sizeof(read_msg));
printf("Child received: %s\n", read_msg);
close(fd[0]);
}
return 0;
}
OUTPUT:
Child received: Hello from parent to child via pipe!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy