#include #include #include #include #define PIPES 1 #define BUFLEN 65536 struct pp { int pfd[2]; }; int main(int argc, char *argv[]) { unsigned int i; unsigned int len; int wlen; struct pp *pvet = calloc(PIPES, sizeof(struct pp)); char *buf = malloc(BUFLEN); if (argc != 2) exit(1); wlen = atoi(argv[1]); if (wlen <= 0 || wlen > BUFLEN) exit(2); for (i = 0; i < BUFLEN; i++) buf[i] = 'o'; // Create. for (i = 0; i < PIPES; i++) { if (pipe(pvet[i].pfd) != 0) { perror("pipe"); abort(); } } // Fill pipes. for (i = 0; i < PIPES; i++) { fprintf(stderr, "Pipe: %05u/%d\n", i, PIPES); for (len = 0; len < BUFLEN; len += wlen) { fprintf(stderr, "\r write: %05u..%u/%d", len, len+(unsigned)wlen, BUFLEN); if (write(pvet[i].pfd[1], &buf[len], wlen) <= 0) { perror("write"); abort(); } } fprintf(stderr, "\n"); } // Consume data from pipes. for (i = 0; i < PIPES; i++) { fprintf(stderr, "Pipe: %05u/%d\n", i, PIPES); if (read(pvet[i].pfd[0], buf, BUFLEN) != BUFLEN) { perror("read"); abort(); } } exit(0); }