In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
System v shared memory
# include # include int shmget (key_t key, size_t size, int shmflg)
Establish: the relationship between processes and shared memory
A non-zero number in key_t key:16.
There are generally two ways to set it.
The first one: call the fotk function
Chapter 2: using IPC_PRIVATE directly
Size: size of shared memory
Shmflg:
The permissions of IPC_CREATIPC_EXCL users, group users, and other users to this memory can be represented by 9 bit, such as 664
Return value: successfully returns the identification number of this piece of shared memory; failure returns-1 errno is set.
# include # include void * shmat (int shmid, const void * shmaddr, int shmflg)
Shmid: created by the shmget function, which is the return value of the shmget function
Shmaddr:
NULL: let the kernel apply for memory space
Non-NULL: create a space with malloc to associate the shared memory shmid with this address. But if it is not an integral multiple of 4K, the kernel will be adjusted up or down.
Shmflg:
SHM_RND: read and write
SHM_RDONLY: read-only
Return value:
Success: return memory address
Failed: return (void *)-1
# include # include int shmdt (const void * shmaddr)
Disassociate a process from shared memory
The return value of shmaddr:shmat
Return value: success 0; failure-1, and set errno.
# include # include int shmctl (int shmid, int cmd, struct shmid_ds * buf)
For shared memory operations, it is more cmd-like, and different operations are performed on shared memory.
Shmid: created by the shmget function, which is the return value of the shmget function
Cmd:
IPC_STAT: get the status of the shared memory
IPC_RMID: Mark to delete shared memory (when the reference count of shared memory becomes 0)
IPC_SET: set the properties of shared memory (modify permissions, modify shmid, etc.)
Wait
Buf:shmid_ds structure
Return value: when cmd is IPC_RMID: success 0; failure-1, and set errno
You can view the status of shared memory with the command [ipcs]
-Shared Memory Segments-key shmid owner perms bytes nattch status0x00007fff 65536 ys 664256 00x00007ffe 98305 ys 664256 00x0000555e 131074 ys 664256 00x00000011 229379 ys 664256 3key: the first parameter specified by function shmget shmid: return value of function shmget owner: perms created by which user: access to this shared memory bytes: size nattch The number of processes using this shared memory status: the status of the shared memory
Summary
The above is introduced by the editor to solve the problem of Linux system v shared memory. I hope it will be helpful to you. If you have any questions, please leave a message for me, and the editor will reply you in time. Thank you very much for your support to the website!
If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.