Unix network programming 2 Reading Notes Chapter 2-System v ipc, unixipc

Source: Internet
Author: User

Unix network programming 2 Reading Notes Chapter 2-System v ipc, unixipc
1. Overview

  • Three types of System v ipc: System V message queue, System V semaphore, and System V shared memory Zone
  • System v ipc shares many similar points between the functions that access them and the information maintained by the kernel for them. This chapter describes all these common attributes.
  • Summarizes all System v ipc functions.
  • The header file sys/types. h defines the data type key_t as an integer, usually a 32-bit integer.
  • The ftok function converts an existing path name and an integer identifier into a key_t value, which is called the IPC key.
  • If the pathname does not exist or is inaccessible to the calling process, ftok returns-1
  • There is no guarantee that the combination of two different pathnames and the same id produces different keys.
3. ipc_perm Structure
  • The kernel maintains an information structure for each IPC object, which is similar to the information maintained by the kernel for files.
4. Create and open an IPC Channel
  • The application has two options for the key value.

  • All three XXXget functions have a parameter named oflag, which specifies the read/write permission bit of the IPC object (the mode Member of the ipc_perm structure) and selects to create a new IPC object, or access an existing IPC object.


  • System v ipc defines its own IPC_XXX constant value, instead of using the O_CREAT and O_EXCL constant values as standard open functions and Posix IPC functions do.
  • Note: The System v ipc function combines the common root permission bits of IPC_XXX to a single oflag parameter. The open function has a parameter named oflag and mode.
5. IPC permission
  • Each time you use a XXXget function to create a new IPC object, the following information is saved to the ipc_perm structure of the object.
  • Although a process can call the XXXctl function to modify the owner ID, the Creator ID never changes. The XXXctl function also allows a process to modify the mode member of an IPC object.
  • Every time a process accesses an IPC object, IPC performs two-level checks. When the object is opened (XXXget function), it is executed once, and will be executed once every time this object is used.
  • The ipc_perm structure contains a seq variable, which is a slot usage serial number. This variable is a counter maintained by the kernel for each potential IPC object in the system. Each time an IPC object is deleted, the kernel increments the corresponding slot number. If it overflows, the cycle is 0.
  • There are two reasons for this counter:
7. ipcs and ipcrm programs
  • It can only be used for System v ipc, but not for Posix IPC
  • Ipcs-q-m-s
  • Ipcrm -- all = msg
8. kernel restrictions
  • Sysctl command



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.