#include #include #include #include #include #include char bigbuf[65536]; void *thr(void *ptr) { int *p = ptr; char tmp[256]; size_t l, t=0; for (;;) { l = read(p[0], tmp, sizeof tmp); if (l <= 0) break; t += l; } printf("read %zu\n", t); } void dummy(int sig) { } int main() { int testpipe[2]; pipe(testpipe); FILE *f = fdopen(testpipe[1], "w"); struct sigaction sa = { .sa_handler = dummy }; sigaction(SIGALRM, &sa, 0); //alarm(1); setitimer(ITIMER_REAL, &(struct itimerval){ .it_interval.tv_usec = 10000, .it_value.tv_usec = 10000 }, 0); char *p = bigbuf; size_t n = sizeof bigbuf, l; memset(p, 42, n); write(testpipe[1], p, n); l = fwrite(p, 1, 512, f); p+=l, n-=l; l = fwrite(p, 1, n, f); pthread_t td; pthread_create(&td, 0, thr, testpipe); while (p+=l, n-=l) l = fwrite(p, 1, n, f); fclose(f); pthread_join(td, 0); }