/* Creates a FIFO, then reads from it as if it were stdin. * As usual, all error checking is omitted so it's easier to see the main ideas. */ #include #include #include int main(int argc, char** argv) { mkfifo(argv[1], S_IRWXU | S_IRWXG | S_IRWXO); int fifo = open(argv[1], O_RDONLY); dup2(fifo, 0); /* 0 is the file descriptor of stdin */ char line[1024]; while (fgets(line, 1024, stdin)) printf("I got this: %s\n", line); }