Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <string.h>
- #define MAX_MESSAGE_SIZE 1024
- int main(int argc, char* argv[]) {
- if (argc != 2) {
- fprintf(stderr, "Usage: %s <subscriber_id>\n", argv[0]);
- exit(EXIT_FAILURE);
- }
- int subscriber_id = atoi(argv[1]);
- char fifo_path[20];
- snprintf(fifo_path, sizeof(fifo_path), "/tmp/ex1/s%d", subscriber_id);
- int pipe_fd = open(fifo_path, O_RDONLY);
- if (pipe_fd == -1) {
- perror("Failed to open named pipe");
- exit(EXIT_FAILURE);
- }
- char message[MAX_MESSAGE_SIZE];
- ssize_t bytes_read;
- while ((bytes_read = read(pipe_fd, message, MAX_MESSAGE_SIZE)) > 0) {
- write(STDOUT_FILENO, message, bytes_read);
- }
- close(pipe_fd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement