#include #include #include #include int main(void) { fd_set wfds; FILE* FPR; int wfd; struct timeval tv; int retval; FPR = fopen("test.txt", "a"); wfd = fileno(FPR); /* Watch stdin (wfd) to see when it is writable. */ FD_ZERO(&wfds); FD_SET(wfd, &wfds); /* Wait up to fifteen seconds. */ tv.tv_sec = 15; tv.tv_usec = 0; retval = select(wfd + 1, NULL, &wfds, NULL, &tv); /* Don't rely on the value of tv now on! */ if (retval > 0) { /* FD_ISSET(0, &wfds) will be true. */ printf("Some event occured.... "); if FD_ISSET(wfd, &wfds) { printf("File writeable.\n"); fprintf(FPR, "Something\n"); printf("%d seconds, %d usecs\n", tv.tv_sec, tv.tv_usec); sleep(5); printf("%d seconds, %d usecs\n", tv.tv_sec, tv.tv_usec); } } else printf("Timeout, File not writeable within 15 seconds.\n"); fclose(FPR); exit(0); }