FIFO reader
Thu Jun 06 2024 00:52:22 GMT+0000 (Coordinated Universal Time)
Saved by
@login
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#define FIFO_PATH "/tmp/myfifo"
#define BUFFER_SIZE 100
int main() {
int fd;
char buffer[BUFFER_SIZE];
// Open the FIFO for reading
fd = open(FIFO_PATH, O_RDONLY);
if (fd == -1) {
perror("open");
exit(EXIT_FAILURE);
}
// Read from the FIFO
read(fd, buffer, BUFFER_SIZE);
// Print the received message
printf("Received: %s\n", buffer);
// Close the FIFO
close(fd);
return 0;
}
content_copyCOPY
Comments