Linux interprocess communication (IPC) has several ways, the following will be briefly described:
one. Pipe
Pipeline is the initial IPC mode supported by Linux. Pipes can be divided into unnamed pipes, named pipes, and so on.
(1) Anonymous pipeline, which has several characteristics:
1) The pipeline is half-duplex and can only support one-way flow of data; it needs to be established when communication between two processes is required. Two pipes;
2) Nameless pipes are created using the pipe() function and can only be used between parent and child processes or between sibling processes;
3) Pipes for both ends of the communication In other words, it is essentially a separate file that exists only in memory;
4) Data read and write operations: A process writes data to the pipeline, and the data written is added to the end of the pipeline buffer. Another process reads data at the head of the buffer in the pipeline.
(2) Named Pipes
A named pipe is also half-duplex, but it allows communication between processes that are not related. Specifically, the well-known pipeline provides a path name associated with it, and exists in the file system in the form of FIFO (first in, first out). This allows even unrelated processes to communicate with each other through FIFOs as long as they have access to the paths already provided.
It is worth noting that it only makes sense to write data to the pipeline when the pipeline has a read end. Otherwise, the process that writes data to the pipe receives the SIGPIPE signal from the kernel; the application can customize the signal handler or ignore the signal directly.
II. Semaphores
Semaphores are counters that control the simultaneous access of resources by multiple threads or processes across processes. It is often implemented as a lock mechanism. Essentially, the semaphore is a protected variable and can only be accessed through initialization and two standard atomic operations (P/V). (P, V operations are also often referred to as wait(s), signal(s))
three. Signals
Signals are one of the oldest methods of interprocess communication used in Unix systems. The operating system signals to a certain process that a predetermined event has occurred; the process that receives the signal can choose to process the signal in different ways. First, the default processing mechanism &mdash can be used; the process is interrupted or exited, and the process is ignored. The signal, as well as the processing function that customizes the signal, performs the corresponding action.
The kernel produces signals for processes to respond to different events, which are the source of the signal. The signal source can be: exception, other processes, terminal interrupt (Ctrl-C, Ctrl+\\, etc.), job control (front, background process management, etc.), allocation amount problem (cpu timeout or file too large, etc.), kernel Notifications (such as I/O Ready, etc.), alarms (timers).
Four. Message Queue
A message queue is a linked list of messages that allows one or more processes to write messages to it, and one or more processes read messages to it. Linux maintains a message queue vector table: msgque to represent all message queues in the system.
Message Queuing overcomes the lack of signaling information, and the pipeline can only support the disadvantages of unformatted byte streams and buffer limitations.
Five. Shared memory
Shared memory is mapped to a piece of memory that can be accessed by other processes. This shared memory is created by one process and then other processes can be mounted into this shared memory. Shared memory is the fastest IPC mechanism, but since Linux itself cannot implement synchronous control and requires user program for concurrent access control, it generally combines other communication mechanisms to achieve inter-process communication, such as semaphores.
Five. Sockets
Sockets are also an inter-process communication mechanism, but the main difference between it and other communication methods is that it can implement process communication between different hosts. A socket can be thought of as an endpoint for interprocess communication. The name of each socket is unique; other processes can access, connect, and communicate data.
After linux rm deletes the file, recovery is more troublesome. Even if it is restored, the file na
In recent years, the open source Linux system can be said to be in the limelight, whether it is pers
The linux shell has its own set of flow control statements, including conditional statements (if),
Too many open files Errors are common faults in Linux systems. Solutions can be easily found on the
Linux setuid and setgid explain
Ten kinds of quick start linux system methods
How to modify the Linux computer name
Detailed Explanation of 7 Weapons in Linux Operating System
Linux prohibits a user from logging in to the system.
How to install Go language in Linux
Problems with installing small input methods under centos
Compile the previous project error solution after IAR upgrade
How to run China Merchants Bank Professional Edition under Linux
What is the reason that the Linux operating system does not need to be defragmented?
How to use Win disk to install Win10 on Win7 system to form dual system
What should I do if the latest preview version of win10 cannot switch Microsoft accounts?
Syskey command: XP and 2000 systems are not commonly used but powerful commands
Win7 can not enter the security mode solution
What is the format of Lnk? How to open a lnk format file
Let Win10 calendar tile show the way of the lunar calendar and weather
awesomeness! Win10 will run on all devices
Comprehensive analysis of network ipv4, ipv6, ipv9 protocol
Master tricks to configure Windows system page file tips
How to activate the new installation of win10 Enterprise Edition?