#include #include #include #define __USE_GNU #include /* mjp@pilcrow.madison.wi.us; 15 Nov 2001 */ /* gcc -o fasync-tty fasync-tty.c */ sig_atomic_t flag_io = 0; void sigio(int signo) { flag_io = 1; } void pdie(char *errtag) { perror(errtag); exit(1); } int main() { int fd; char buf[512]; char * tty; if (signal(SIGIO, sigio) == SIG_ERR) pdie("signal"); tty = ttyname(fileno(stdin)); if (!tty) pdie("tty/stdin"); fd = open(tty, O_ASYNC|O_RDONLY); if (fd == -1) pdie("open"); if (fcntl(fd, F_SETOWN, getpid()) == -1) pdie("F_SETOWN"); printf("%s open()d O_ASYNC, F_SETOWN'd\n", tty); printf("A line of input, please...\n"); (void) fgets(buf, 512, stdin); printf("O_ASYNC set? %s\n", (fcntl(fd, F_GETFL) & O_ASYNC) ? "Yes" : "No"); printf("O_ASYNC respected? %s\n", flag_io ? "Yes" : "No (bummer)"); exit(0); }