For this mounth the article will be more technique than usual .
I try to explain you an linux concept that for me is under exploited in our linux application. So i write this post to hilight this concept that i will use in a work project.
this concept is the pipe linux
The pipe concept
If you are a linux user you have certainly cross the path of the pipe command |. But did you know that there is two different type of pipe. And more over that did you know that you can use pipe as a connection protocol. I didn't until i need to create a new application based on module and find this way of communicate between process.
So i will share this discover with you. So there are to type of pipe
The uname pipe is that you can find and use in every day commande for exemple one i regularely used:
ls -ltr | grep .md
This two command will list all the Markdown file in a repository.
To do so ls -ltr and grep will be execute as separet processes and the uname pipe allows them to communicate.
what's append is that the ls write to the pipe and send an end of stream marker when finish to write and the grep is the reader. After the reading the unmame pipe will be automaticly delete.
An unnamed pipe has no backing file: the system maintains an in-memory buffer to transfer bytes from the writer to the reader. Once the writer and reader terminate,
the buffer is reclaimed, so the unnamed pipe goes away.
The name pipe will fallow the same principe as an uname pipe except that he as a backing file and a distinct API.
To create a name pipe use the command
Multiple processes can access this special file for reading and writing like any ordinary file.
The name pipe can provides unidirectional communication.
The name pipe have strict FIFO behavior: the first
byte written is the first byte read, the second
byte written is the second byte read, and so
to close the pipe
if you want an example of two way pipe communication you can find a very good article here :
or this video is also very helpfull
Using an anonymous pipe instead of a named pipe depends on the characteristics we’re looking for. Some of them can be persistence, two-way communication, having a filename, creating a filter, and restricting access permissions among others.