1-4_ Basic Concepts _ interprocess communication and synchronization

Source: Internet
Author: User

Memory Mapping

A process that calls the system function mmap () Creates a new memory map in its virtual address space.

The mappings are divided into two categories:

1. File mapping: Maps a portion of a file into the virtual memory of the calling process. Once the mapping is complete, access to the file-mapped content translates into byte operations on the corresponding memory area. The mapping page is automatically loaded from the file as needed.

2, a contrast is no file with the corresponding anonymous mapping, the content of its mapping page will be initialized to 0.

The memory mapped by one process can be shared with the mappings of other processes. There are two ways to achieve sharing:

The first is that all two processes map the same part of a file

The second is that the child process created by fork () inherits the mappings from the parent process.

When two or more processes share a page, does one of the processes change the content of the page as seen by other processes? This depends on the flag parameter that was passed in when the mapping was created. If the passed flag parameter is private, the modification of a process to the mapped content is not visible to other processes, and the changes are not actually implemented on the file, and if the incoming flag is shared, modifications to the mapped content will be seen by other processes, and these changes will cause changes to the file.

Memory mapping is used in a number of ways, including: Initializing a process's text segment, memory (content-filled with 0) allocations, file I/O (that is, mapped memory I/O), and interprocess communication (through shared mappings) in the appropriate segment of the executable file.

interprocess communication (IPC) mechanism

The information in the read-write disk file is one of the methods for interprocess communication. However, for many programs, this approach is slow and inflexible. As a result, Linux provides a rich inter-process communication (IPC) mechanism.

Signal (signal), used to indicate the occurrence of an event.

Pipeline (the "|" that the shell user is familiar with) operator) and FIFO, which are used to pass data between processes.

Socket (socket) for passing data between processes running on the same host or on different hosts that are networked.

File locking, which allows a process to lock parts of a file to prevent other processes from reading or updating the contents of the file.

Message Queuing, which is used to exchange messages (packets) between processes.

Semaphore (semaphore), used to synchronize process actions.

Shared memory, allowing two and more than two processes to share a piece of memory. When a process changes the contents of shared memory, all other processes are immediately aware of the change.

Signal

Although the signal is regarded as one of the methods of IPC, its wide application in other aspects is more common.

People often refer to the signal as a "software outage." When a process receives a signal, it means that an event or an abnormal condition occurs. There are many types of signals, each identifying different events or situations. Different integers are used to identify various signal types and are defined in the form of sigxxxx symbols.

The kernel, other processes (as long as they have the appropriate permissions), or processes themselves can send signals to the process.

The kernel can send a signal to a process when one of the following conditions occurs:

The user types the interrupt character (usually control-c)

One of the process's child processes has been terminated.

The timer (alarm clock) set by the process has expired.

The process attempted to access an invalid memory address.

In the shell, you can use the KILL command to send a signal to a process. Inside the program, the system calls Kill () to provide the same functionality.

When the signal is received, the process takes one of the following actions according to the signal:

Ignore the signal.

"Killed" by the signal.

Hang first, and then wake up with a special signal.

In the case of most signal types, the program chooses not to take the default signal action, but rather ignores the signal (which is useful when the default processing behavior of the signal is not to ignore the signal) or to establish its own signal processor.

A signal processor is a programmer-defined function that is automatically called when a process receives a signal and performs the corresponding action based on the condition of the signal.

The signal is in a pending state from the time it is generated until it is delivered to the process. Typically, the system will deliver signals that are in a pending state at the time of the next dispatch of the receiving process. If the receiving process is running, the signal is delivered immediately. However, the program can incorporate the signal into so-called "signal masking" to block the signal. If the resulting signal is in the "Signal Screen" column, the signal will remain suspended until the group setting for the signal is lifted.

1-4_ Basic Concepts _ interprocess communication and synchronization

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.