Home > Common Problem > What are the methods of inter-process communication?

What are the methods of inter-process communication?

coldplay.xixi
Release: 2023-01-13 00:31:52
Original
77730 people have browsed it

The methods of inter-process communication include: 1. Pipes usually refer to unnamed pipes, which are the oldest form of IPC in UNIX systems; 2. FIFO, which is a file type; 3. Message queue, which is a linked list of messages. , stored in the kernel; 4. The semaphore is a counter; 5. Shared memory.

What are the methods of inter-process communication?

#The operating environment of this article: Windows 7 system, Dell G3 computer.

The methods of inter-process communication are:

1. Pipes

Pipes, usually refer to unnamed pipes, are UNIX systems The oldest form of IPC.

Features:

  • It is half-duplex (i.e. data can only flow in one direction), with fixed read and write ends.

  • It can only be used for communication between processes that have affinity relationships (also between parent-child processes or sibling processes).

  • It can be regarded as a special file, and ordinary read, write and other functions can also be used to read and write it. But it is not an ordinary file, does not belong to any other file system, and only exists in memory.

2. FIFO

FIFO, also known as named pipe, is a file type.

1. Features

  • FIFO can exchange data between unrelated processes, unlike nameless pipes.

  • FIFO has a path name associated with it, and it exists in the file system as a special device file.

3. Message Queue

The message queue is a linked list of messages, stored in the kernel. A message queue is identified by an identifier (queue ID).

Features

  • The message queue is record-oriented, and the messages in it have a specific format and a specific priority.

  • The message queue is independent of the sending and receiving processes. When the process terminates, the message queue and its contents are not deleted.

  • The message queue can realize random query of messages. The messages do not have to be read in first-in, first-out order, but can also be read according to the type of message.

4. Semaphore

The semaphore (semaphore) is different from the IPC structure that has been introduced. It is a counter. Semaphores are used to implement mutual exclusion and synchronization between processes, rather than storing inter-process communication data.

Features

  • Semaphore is used for inter-process synchronization. To transfer data between processes, it needs to be combined with shared memory.

  • The semaphore is based on the PV operation of the operating system, and the program's operations on the semaphore are all atomic operations.

  • Each PV operation on the semaphore is not limited to adding 1 or subtracting 1 to the semaphore value, but can also add or subtract any positive integer.

  • Supports semaphore groups.

5. Shared Memory

Shared Memory (Shared Memory) refers to two or more processes sharing a given storage area.

Features

  • Shared memory is the fastest type of IPC because the process directly accesses the memory.

  • Because multiple processes can operate at the same time, synchronization is required.

  • Semaphore Shared memory is usually used together, and semaphores are used to synchronize access to shared memory.

If you want to learn more about programming, please pay attention to the php training column!

The above is the detailed content of What are the methods of inter-process communication?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template