#include #include #include #include #include #include #include #include #include #define FIFO "fifo" int main() { int fd; int pid; fd_set set; struct timeval tv; assert(unlink(FIFO) == 0 || errno == ENOENT); assert(mkfifo(FIFO, DEFFILEMODE) == 0); signal(SIGCHLD, SIG_IGN); pid = fork(); if (pid == 0) { char c; int ret; fd = open(FIFO, O_RDONLY); FD_ZERO(&set); FD_SET(fd, &set); tv.tv_sec = 3; tv.tv_usec = 0; ret = select(fd+1, &set, NULL, NULL, &tv); if (ret == 0) printf("child: select() timeout\n"); else printf("child: number readable of files: %d\n", ret); exit(0); } else { fd = open(FIFO, O_WRONLY); sleep(1); printf("parent: exit\n"); } return (0); }