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
Today I will talk to you about clearing floats. B...
Tencent QQ’s homepage has been redesigned, and Web...
1. Pull the image First, execute the following co...
The problem is as follows: I entered the command ...
How to determine what this points to? ①When calle...
Create a table CREATE TABLE `map` ( `id` int(11) ...
When it comes to switching directories under Linu...
Table of contents url module 1.parse method 2. fo...
I have always wanted to learn about caching. Afte...
Table of contents Preface && Operator || ...
Overview Binlog2sql is an open source MySQL Binlo...
Before reading this article, I hope you have a ba...
MongoDB Installation Choose to install using Yum ...
It is standard for websites to enable SSL nowaday...
VMware version: VMware-workstation-full-16 VMware...