UNIX network programming 2 Reading Notes Chapter 2-Introduction

Source: Internet
Author: User
1. Overview 2. process, thread, and information sharing

There are multiple ways to share information between Unix processes: Pay attention to the location of the kernel

  • The two processes on the left share some information stored on a file in the file system. To access this information, each process must traverse the kernel.
  • The two processes in the middle share some information in the kernel. Pipelines, System V message queues, and System V semaphores are all shared.
  • The two processes on the right have a shared memory zone that both parties can access. Once this shared memory area is configured for each process, the data in the shared memory area can be accessed without involving the kernel.
  • Note: The above IPC technology can act on any number of processes.
Thread
  • IPC between multiple processes, IPC of multiple threads in a single process
  • From the perspective of IPC, a global variable shared by all threads in a given process (that is, the concept of shared memory zone is built-in to this model ).
  • However, we must pay attention to the synchronous access to global data among various threads.
  • Although synchronization is not a clear IPC form, it does come along with many forms of IPC to control access to some shared data.
3. Continuity of IPC objects
  • Demonstrate three types of continuity: determine the duration of the IPC object
  • 1. the IPC object that persists with the process until the last process that opens the object closes the object. Such as pipelines and FIFO
  • 2. the IPC object that persists with the kernel until the kernel re-runs or explicitly deletes the object. For example, System V message queue, semaphore, and shared memory zone. POSIX message queues, semaphores, and shared memory must at least be consistent with the kernel, but it can also be consistent with the file system, depending on the implementation.
  • 3. An IPC object that persists with the file system until it is explicitly deleted. The value of this object is retained even if the kernel is retained. If POSIX message queues, semaphores, and shared memory areas are implemented using ing files, they continue with the file system.

    In most cases, IPC does not have the intention to continue to exist after the system reapplies, because it is impossible for a process to survive after reapplies. In addition, it is required that the persistence of the file system may reduce its performance, and a basic design goal of IPC is high performance.

4. namespace
  • When two or more unrelated processes exchange information with each other using some type of IPC object, the IPC object must have a certain form of name or identifier. In this way, a process (usually a server) can create this IPC object, while other processes can specify the same IPC object.
  • The pipeline has no name (so it cannot be used between unrelated processes ).
  • FIFO has a Unix path name in the file system as its identifier (so it can be used between unrelated processes ).
  • For a given IPC type, a set of possible names is called its namespace. Namespace is very important. For all forms of IPC except common pipelines, names are the means by which customers and servers connect to each other to exchange messages.

  • Summarizes the naming conventions used by different forms of IPC

5. Effect of fork, exec, and exit on IPC objects

  • 1. Considering unknown synchronization variables (mutex lock, condition variable, read/write lock, POSIX memory-based semaphore), calling fork from a process with multiple threads will become messy.
  • 2. System v ipc is not enabled or disabled in three forms. To access these three forms of IPC objects, you only need to know their identifiers, so any process that knows the identifiers can access them.
6. the IPC example index table in the book
  • File Server: Customer Service-server application. The customer sends a path name to the server, and the server returns the content of the file to the customer.

  • Producer-consumer: one or more threads or processes (producers) place data in a shared buffer, and one or more threads or processes (consumers) operate the data in the shared buffer.

  • Serial number continues to increase by 1: one or more threads or processes continuously increase by 1 for a shared serial number. The serial number is sometimes in a shared file or in the shared memory.
7. Summary
  • Four main fields:
    1. Message transmission: pipelines, FIFO, and message queues
    2. Synchronization: mutex lock, condition variable, read/write lock, semaphore
    3. Shared Memory zone: anonymous shared memory zone and famous shared memory Zone
    4. Process call: Solaris door, Sun RPC

UNIX network programming 2 Reading Notes Chapter 2-Introduction

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.