Created
September 6, 2017 14:23
-
-
Save hamadu/ca9404fa8ed02325eb7008d050fd74cc to your computer and use it in GitHub Desktop.
fifo
This file contains 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 <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; | |
} |
This file contains 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 <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; | |
} |
This file contains 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 <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