When I echo into files at some arbitrary locations in Linux, i.e. echo > /tmp/file, some running processes respond. Is this IPC via file pipe?
Does this mean a running process always open the file to be read? But so, how can the file be written, since the file stream is locked by by its own process?
If you want use a file to communicate with another process, you should have a look at
man fifo.I’ll report here just the first lines:
I think this is what you need.
Just think to it as a buffer. It must be opened both for reading and for writing by different process. The process who’s reading will be blocked until the writing process doesn’t write on it. When the writing process finish to write, close the file and that is the green light for the reading process to start empty the buffer. It’s a FIFO, so the first line written will be the first line read. Then the writing process can open it again and they start again.
You can create a FIFO with
mkfifo. Have a look toman mkfifo.