Nameless pipe: Primarily for process communication (I feel it has a lot of limitations)
Features: It is not a file system and cannot be accessed by name, which is the biggest difference between it and the famous pipe. A nameless pipe is just something inside a system's memory.
Half-duplex mode, the data can only flow to One direction (the teacher gave us an example is the water plant water to the residents of water, it is not possible to flow backwards, right).
Communication between processes, but only affinity processes can communicate? For example, a parent-child process: Because in a parent-child process, the child process copies the data segment of the parent process, which allows the two processes to have a connected relationship when communicating.
Let's take a look: nameless pipe creation, write, read, close (I'm using the Liunx system CentOS)
This function is to create a pipeline that will build the return value of the successful function is 0, otherwise the failure is to return-1, and return the error number, errno.
When creating this nameless pipe, define an array with a size of 2, which is used to hold the handle (the file descriptor).
The nameless pipe has a read end, pipefd[0]---------------------read (fd,buf,sizeof (BUF)), and the Read function is the system's reading function, which reads the contents of the file into the BUF, Note that when communicating between processes using nameless pipes, we need to call the kernel functions of the system and not call the library functions.
The nameless pipe has a write end, pipefd[1]---------------------write (fd,buf,sizeof (BUF)), and the Write function is the writing function of the system, which writes the contents of the buf inside the file.
The next step is to close the read and write ends. Close (Fd[0]), close (fd[1]);
I wrote an example of a nameless pipe myself:
This program is a child process that writes data, and the parent process reads the data so that communication between processes is realized. The operating result is:
This is I write a very see of the program, I am also a novice, there must be a lot of shortcomings, but also ask you to mention good suggestions.
Process Communications-nameless pipes