Created
October 27, 2016 17:12
-
-
Save peko/b427cfa417ff8af8fb6c2921c8677511 to your computer and use it in GitHub Desktop.
fast_writer | slow_reader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
gcc -o slow_reader slow_reader.c | |
gcc -o fast_writer fast_writer.c | |
./fast_writer | ./slow_reader |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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