// gcc -Os -Wall -o statuscat statuscat.c #include #include #include #include int main() { int buflen = getpagesize(); int rc, chunklen, idx; unsigned char buffer[buflen]; long long old_total = 0, total = 0; time_t time_start = time(NULL) - 1; int retval = 0; signal(SIGPIPE, SIG_IGN); while (1) { rc = read(0, buffer, buflen); if (rc < 0) { sleep(2); perror("COPY: read error"); goto error; } if (rc == 0) break; for (idx = 0, chunklen = rc; idx < chunklen; idx += rc) { rc = write(1, buffer+idx, chunklen-idx); if (rc <= 0) { sleep(2); perror("COPY: write error"); goto error; } } total += chunklen; if (total - old_total >= 1024*1024*64) { time_t time_now = time(NULL); fprintf(stderr, "COPY: %Ld MB (%Ld MB/sec)\r", total / (1024*1024), (total / (1024*1024)) / (time_now-time_start)); old_total = total; } } if (0) { error: retval = 1; } time_t time_now = time(NULL); fprintf(stderr, "COPY: %Ld MB (%Ld MB/sec)\n", total / (1024*1024), (total / (1024*1024)) / (time_now-time_start)); return retval; }