#include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #define FIFO_FILE "/tmp/fifo" #define MAX_SIZE 1024 int main(void) { int fd; char str[MAX_SIZE] = { 0, }; if (-1 == (fd = open(FIFO_FILE, O_WRONLY))) { perror("open() 실행에러"); exit(1); } fgets(str, MAX_SIZE, stdin); write(fd, str, strlen(str)); //쓰는 부분 close(fd); }
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <errno.h> #define FIFO_FILE "/tmp/fifo" #define BUFF_SIZE 1024 int main(void) { int cnt = 3; int test = 0; int counter = 0; int fd; char buff[BUFF_SIZE] = { 0, }; if (-1 == (mkfifo(FIFO_FILE, 0666)) && (errno != EEXIST)) { perror("mkfifo() 실행에러"); exit(1); } if (-1 == (fd = open(FIFO_FILE, O_RDWR))) { perror("open() 실행에러"); exit(1); } read(fd, buff, BUFF_SIZE); //읽는 부분 printf("%d: %s", counter++, buff); //출력 close(fd); }