IPC using pipes

This commit is contained in:
2024-05-01 14:51:17 +05:30
parent 1b1acabe42
commit 52bad283ed
3 changed files with 102 additions and 0 deletions

23
Pipes/Pipes_demo.c Normal file
View File

@@ -0,0 +1,23 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
int main(int argc, char* argv[]) {
int pfds[2];
char buf[30];
if (pipe(pfds) == -1) {
perror("pipes");
exit(1);
}
printf("writing to file descriptor #%d\n", pfds[1]);
write(pfds[1], "test", 5);
printf("reading from file descriptor #%d\n", pfds[0]);
read(pfds[0], buf, 5);
printf("read \"%s\"\n", buf);
return 0;
}