Process communication is the exchange of information between processes (transferring data). The current computer system provides a multitasking parallel environment that requires the creation of processes for each task, whether it be an application or a system program.
Each process is independent of each other, and different processes run in their own different memory spaces, so information transfer between processes cannot be done directly through variables or other data structures, but only through interprocess communication.
inter-process communication mode: Signal , pipelines, semaphores, message queues, shared memory, Socket
Today, we introduce the communication between programs through pipelines. Pipelines are divided into famous pipes and nameless pipes.
(pipe file) (Half-duplex communication: Data flow is unidirectional.) )
Well- known pipeline: There is a file identifier (file name) in the file system, but the pipe file does not occupy disk space and the data that needs to be passed is cached in the memory area. Can be used to run any of the two processes in a system. (with attribute information,inode node exists on disk)
Nameless pipe: Used for communication between parent and child processes. No attribute information, no inode nodes.
before we could get data from each other through files. (Put data on disk) get through I/O (slow)
Pipeline File Creation: (command)mkfifo file name
(function) Int Mkfifo(const char *pathname ,mode_t mode)
The first parameter is going to create a private file in the file system, and the second parameter specifies FIFO Read and Write permissions.
cannot create a pipe file with open
Operation of pipeline files:
Open : int Open (char *path, int flag)
read: int read (int fd, void *buff,size_t size)
write: int write (int fd, void *buff, size_t size)
Close :int Close (int fd)
1. Open opens a pipe file with read-only, and The Open will block until a process opens the pipeline file with write-only or read-write.
2 . open to write-only opens a pipeline file, Open will block the run until a process opens the pipeline file with read-only or read-write.
3 . The read function also blocks the run until there is data or shutdown in the pipeline.
4, write function will also block the run, when writing too much is written to block the operation to wait until the data read to go on to write.
A well-known pipeline of interprocess communication