FIFO communication (first in first out) FIFO named pipe, which enables communication between non-related processes.
man 3 mkfifo #include <sys/types.h> #include <sys/stat.h> int mkfifo(const char *pathname, mode_t mode); Note: FIFOs When opening a fifo file, the read end will block waiting for the write end to open, and the write end will also block waiting for another end to open. Code example: #include <stdio.h> #include <stdlib.h> #include <sys/wait.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> #include <string.h> int main(int argc, char *argv[]) { if(argc != 2) { printf("./a.out filename1\n"); return -1; } printf("begin open w\n"); int o_ret = open(argv[1], O_WRONLY); printf("end open w\n"); char buf[256]; int num = 0; while (1) { memset(buf, '\0', sizeof(buf)); sprintf(buf, "xiaoming--%d", num++); printf("strlen(buf) = %d\n", strlen(buf)); write(o_ret, buf, strlen(buf)); sleep(1); } close(o_ret); return 0; } file_r.c Read side #include <stdio.h> #include <stdlib.h> #include <sys/wait.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> #include <string.h> int main(int argc, char *argv[]) { if(argc != 2) { printf("./a.out filename1\n"); return -1; } printf("begin open r\n"); int o_ret = open(argv[1], O_RDONLY); printf("end open r\n"); char buf[256]; int num = 0; while (1) { memset(buf, '\0', sizeof(buf)); read(o_ret, buf, sizeof(buf)); printf("strlen(buf) = %d\n", strlen(buf)); printf("read is%s\n", buf); } close(o_ret); return 0; } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: 4 ways to modify MySQL root password (summary)
>>: jQuery implements shopping cart function
hint This plug-in can only be accessed under the ...
Here are the types of data that can be verified l...
Table of contents 1. Introduction 2. Main text 2....
Classical color combinations convey power and auth...
Table of contents 1. Problems encountered 2. Idea...
1. Let's look at a table creation statement f...
1. Source of the problem A friend @水米田 asked me a...
The specific code of the sliding button made with...
doctype is one of them: <!DOCTYPE HTML PUBLIC &...
Problem Description In the login page of the proj...
First of all, you can understand the difference b...
1. Design source code Copy code The code is as fol...
When writing my own demo, I want to use display:f...
In the process of writing the project page, I enc...
•There are many selectors in CSS. What will happe...