Inter-process communication via file

When I echo to files in some arbitrary places on Linux, i.e. echo > /tmp/file , some running processes respond. Is it IPC through the file channel?

Does this mean that a running process always opens a file for reading? But so how can a file be written, since the file stream is blocked by its own process?

+4
source share
1 answer

If you want to use the file to communicate with another process, you should look at man fifo .

I will report here only the first lines:

 NAME fifo - first-in first-out special file, named pipe DESCRIPTION A FIFO special file (a named pipe) is similar to a pipe, except that it is accessed as part of the file system. It can be opened by multiple processes for reading or writing. When processes are exchanging data via the FIFO, the kernel passes all data internally without writing it to the file system. Thus, the FIFO special file has no contents on the file system; the file system entry merely serves as a reference point so that processes can access the pipe using a name in the file system. 

I think this is what you need.

Think like a buffer. It should be open both for reading and writing in various ways. The reading process will be blocked until the writing process writes to it. When the writing process ends for writing, close the file, and this is the green reading progress bar to start the empty buffer. This is a FIFO, so the first line will be the first line read. Then the recording process can open it again and they will start again.

You can create a FIFO using mkfifo . Take a look at man mkfifo .

+6
source

All Articles