Skip to content

Instantly share code, notes, and snippets.

@hamadu
Created September 6, 2017 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamadu/ca9404fa8ed02325eb7008d050fd74cc to your computer and use it in GitHub Desktop.
Save hamadu/ca9404fa8ed02325eb7008d050fd74cc to your computer and use it in GitHub Desktop.
fifo
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(int argc, char* argv[]) {
mkfifo("fifo", S_IRWXU);
while (1) {
sleep(1);
}
return 0;
}
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
int fd = open("fifo", O_RDONLY);
char buf[6];
while (1) {
int num = read(fd, buf, 5);
if (num == 0) {
break;
}
printf("%s\n", buf);
}
return 0;
}
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
int fd = open("fifo", O_WRONLY);
char data[3] = {'c', 'a', 't'};
for (int i = 0 ; i < 100 ; i++) {
write(fd, data, 3);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment