I can not find an example of how to read the data in fifo. In user mode, I create a fifo and record the data, here is an example:

#include<stdio.h> #include<string.h> #include<stdlib.h> #include<sys/socket.h> #include<arpa/inet.h> #include<unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include<pthread.h> #include <sys/stat.h> #define MAX_BUF 999999 int main() { int i; int fd,d=0; char * myfifo = "/tmp/myfifo3"; char buf[MAX_BUF],src[]="1234567890qwertyuiop",src2[2]="98"; if((mkfifo(myfifo, 0666)) == -1) { fprintf(stderr, "Невозможно создать fifo\n"); } else{mkfifo(myfifo, 0666);} fd = open(myfifo, O_WRONLY); for (i=99999999;i>0;i--){ if(fd = open(myfifo, O_WRONLY)== -1){ fprintf(stderr, "Невозможно открыть fifo\n"); }else { d=1+(int) (10.0*rand()/(RAND_MAX+1.0)); src[0]=src[d]; write(fd, src, sizeof(src)); close(fd); } } return 0; } 

And how to work with fifo in kernel linux?

  • one
    And why do you need a fifo to the core? This is mildly non-trivial you will most likely have to create a separate kernel-level process to work with it. For such purposes, there is a / proc mechanism in the kernel and it is worth working through it, and not through fifo - Mike
  • one
    On nix systems, you can work with any object of the file type nonblocking. put the appropriate flags through fcntl and work. If suddenly the standard handlers / proc do not allow this, you can attach any handlers that you need through the file_operations structure. This includes processing the O_NONBLOCK flags and when they are set to return control from the read / write functions with the corresponding errors when the receive buffers are full or the transmit buffers are empty - Mike
  • one
    for example fs / proc / kmsg.c: kmsg_read () is able to handle O_NONBLOCK and judging by its only line responsible for this, it is done elementary, as I said, look at the flag in the file structure and if it is, can we check if we can perform the operation right now if not, return -EAGAIN - Mike
  • one
    What is a "record". If the module that declared this file has a write handler to the file, then you can write to such a file from usermode. I think you can write handlers to create new files, although I’m not sure if you need to study the kernel - Mike
  • one
    Well, so I said, if the module on the kernel side specified the write handler function (file_operations-> write), it can. All files in / proc / sys work this way, through them userspace writes settings to the kernel. - Mike

0