Communication between processes in Linux Network Programming (I): inter-process communication Overview

Source: Internet
Author: User

I. sequential program and concurrent program features

Sequential program features

Sequence
Closed: (closed runtime environment)
Certainty
Reproducibility

Concurrent program features

Sharing
Concurrency
Randomness


2. Process mutex

1. Because various processes need to share resources and some resources need to be mutually exclusive, the processes compete to use these resources. The process is mutually exclusive.
2. Some resources in the system can only be used by one process at a time. Such resources are called critical resources or mutually exclusive resources.
3. The program segment involving mutex Resources in the process is called the critical section.

Example:


Assume that x = 1; When process a has completed the judgment x> 0, the time slice rotates to B, and process B also judges x> 0, and then executes X --, that is, x = 0, after that, we rotate to continue executing a, and then execute X -- it is obvious that the system logic has encountered an error.


3. Process Synchronization

Process Synchronization means that multiple processes need to work together to complete a task. Example:


The P1 and P2 processes work together. Only when P2 is closed can P1 Start the vehicle. P1 runs normally and P2 starts selling tickets. When P1 stops, P2 can open the door;

That is, you must wait for the other party to complete an operation before you can continue running the operation.


Iv. Purpose of inter-process communication

1. Data Transmission: A process needs to send its data to another process.
2. Resource Sharing: multiple processes share the same resource.
3. Notification event: a process needs to send a message to another process or a group of processes to notify it of an event (such as notifying the parent process when the process is terminated ).
4. Process Control: some processes want to completely control the execution of another process (such as the debug process). At this time, the control process wants to block all the traps and exceptions of another process, and be able to know its status changes in time.


5. Classification of inter-process communication

File
File lock
Pipelines (PIPE) and named pipelines (FIFO)
Signal (signal)
Message Queue
Shared Memory
Semaphores
Mutex
Condition variable
Read/write lock
Socket)

Note that message queues, shared memory, and semaphores are defined in System V and POSIX standards, while mutex, conditional variables, and read/write locks are defined only in POSIX standards.


6. Three Methods for sharing information between processes


1. Process Persistence: the process persists until the last process is started. (For example, pipe and FIFO)
2. kernel Persistence: always exists until the kernel is automatically lifted or explicitly deleted (such as system v message queue, shared memory, semaphore)
3. Continuous with the file system: it exists until it is explicitly deleted, even if the kernel auto-lift still exists. (POSIX message queue, shared memory, and semaphores are implemented using ing files)


That is, POSIX message queues, shared memory, and semaphores are at least sustained with the kernel. If they are implemented using ing files, they are sustained with the file system.


Refer:

Chapter 1 TCP/IP details

UNP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.