Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the shared memory of Linux system

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly analyzes the relevant knowledge points of how to understand the shared memory of the Linux system, the content is detailed and easy to understand, the operation details are reasonable, and has a certain reference value. If you are interested, you might as well follow the editor to have a look, and follow the editor to learn more about how to understand the shared memory of the Linux system.

Shared memory is used in process communication. Shared memory refers to the shared memory of two different processes An and B, which means that the same piece of physical memory is mapped to the respective process address space of process An and B.

The current system is Centos, execute the ipcs command to check

Description:

The first column is the key of shared memory

The second column is the shared memory number shmid

The third column is the created user owner

The fourth column is the permission perms

The fifth column is the created size bytes

The sixth column lists the number of processes connected to shared memory nattach

The seventh column is the status status of the shared memory. The display of "dest" indicates that the shared memory segment has been deleted, but users are still using it, and "dest" is displayed when the mode field of that memory is set to SHM_DEST. When the user calls the IPC_RMID of shmctl, the memory first checks how many processes are associated with the memory. If the association number is 0, the shared memory will be destroyed. Otherwise, the mode bit of the mod of this memory will be set to SHM_DEST, and if none of the processes are used, the shared memory will be deleted.

The specific usage is summarized as follows: 1. Display all IPC facilities

# ipcs-a2. Show all message queuing Message Queue

# ipcs-Q3, display all semaphores

# ipcs-S4, display all shared memory

# ipcs-M5. Display details of IPC facilities

# ipcs-Q-I idid corresponds to shmid, semid, msgid, etc. -Q corresponds to the type of facility (queue), check the semaphore details of the usage of-s, and view the shared memory usage of-m.

6. Display the limit size of IPC facilities

# ipcs-m-lmurm corresponds to the type of facility. Optional parameters include-Q,-m,-s.

7. Display the permission relationship of the IPC facility

# ipcs-c # ipcs-m-c # ipcs-Q-c # ipcs-s-c8, showing the process ID that recently visited the IPC facility.

# ipcs-p # ipcs-m-p # ipcs-Q-p9, showing the last operating time of the IPC facility

# ipcs-t # ipcs-Q-t # ipcs-m-t # ipcs-s-T10, showing the current status of IPC facilities

The ipcs command on # ipcs-uLinux does not support the-b and-o instructions on UNIX, and the-l and-u instructions are not supported in UNIX, so you need to pay attention to this problem when writing cross-platform scripts.

Delete IPC

Ipcrm-m |-Q |-s shm_id for example, we have created a shared memory for KEY with 0x12345678, and we can delete the shared memory area directly using ipcrm-M 0x12345678.

The following command frees all allocated shared memory:

Ipcs-m | awk'$2 ~ / [0-9] + / {print $2}'| while read s; do sudo ipcrm-m $s; which versions of doneLinux are available in Linux: Deepin, UbuntuKylin, Manjaro, LinuxMint, Ubuntu and other versions. Among them, Deepin is one of the best-developed Linux distributions in China; UbuntuKylin is a derivative release based on Ubuntu; Manjaro is a Linux release based on Arch; LinuxMint's default Cinnamon desktop is similar to Windows XP's easy-to-use; Ubuntu is the Linux operating system based on desktop applications.

This is the end of the introduction on "how to understand the shared memory of the Linux system". More related content can be searched for previous articles, hoping to help you answer questions and questions, please support the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report