writer.c (554B)
1 #include <fcntl.h> 2 #include <sys/stat.h> 3 #include <sys/types.h> 4 #include <unistd.h> 5 #include <stdio.h> 6 7 8 int main() 9 { 10 int fd; 11 char * myfifo = "/tmp/myfifo"; 12 13 /* create the FIFO (named pipe) */ 14 mkfifo(myfifo, 0666); 15 16 /* write "Hi" to the FIFO */ 17 fd = open(myfifo, O_WRONLY | O_ASYNC); 18 write(fd, "Hi", sizeof("Hi")); 19 printf("Sent hi"); 20 sleep(1); // sleep until interrupt (SIGIO) 21 write(fd, "you", sizeof("you")); 22 printf("Sent you"); 23 close(fd); 24 25 /* remove the FIFO */ 26 unlink(myfifo); 27 28 return 0; 29 }