Skip to content

Instantly share code, notes, and snippets.

@peko
Created October 27, 2016 17:12
Show Gist options
  • Save peko/b427cfa417ff8af8fb6c2921c8677511 to your computer and use it in GitHub Desktop.
Save peko/b427cfa417ff8af8fb6c2921c8677511 to your computer and use it in GitHub Desktop.
fast_writer | slow_reader
#include <stdio.h>
int main(int argc, char** argv) {
char buf[256];
for(int i = 0; i < 1000000; i++){
fprintf(stdout, "line %d\n", i);
fprintf(stderr, "[wr] line %d writed\n", i);
}
}
#!/bin/bash
gcc -o slow_reader slow_reader.c
gcc -o fast_writer fast_writer.c
./fast_writer | ./slow_reader
#include <stdio.h>
#include <unistd.h>
int main(int argc, char** argv) {
char *line = NULL;
size_t size;
while(getline(&line, &size, stdin) != -1) {
printf("[rd] %s", line);
usleep(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment