fifo.c
Fri May 10 2024 13:42:37 GMT+0000 (Coordinated Universal Time)
Saved by
@exam123
#include <sys/ipc.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <sys/stat.h> // Include this header for mkfifo
int main()
{
int fd[2], i, j, x, k;
pid_t pid;
char string[] = "hello";
char b[80];
i = mkfifo("f1.txt", 0666);
pid = fork();
if (pid == 0)
{
j = open("f1.txt",O_RDWR);
write(j, string, strlen(string));
close(j);
}
else
{
k = open("f1.txt", O_RDONLY);
x = read(k, b, sizeof(b));
printf("Received String: %s\n", b);
close(k);
}
return 0;
}
content_copyCOPY
Comments