In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Shmget ()-establish shared memory copyright notice: please indicate the original origin and author information of the article and this statement in the form of hyperlink when reprinting
Http://leezen.blogbus.com/logs/19564086.html
# include
# include
Int shmget (key_t key, size_t size, int shmflg)
Key_t key
Key identifies the key value of shared memory: 0/IPC_PRIVATE. When the value of key is IPC_PRIVATE, the function shmget () will create a new shared memory; if the value of key is 0 and the flag IPC_PRIVATE is set in the parameter shmflg, a new piece of shared memory will also be created.
In IPC communication mode, whether using message queues, shared memory, or even semaphores, each IPC object (object) has a unique name, called "key". Through keys, processes can identify the objects being used. Keys are related to IPC objects as file names are to files. Through file names, processes can read and write data in a file, and even multiple processes can share a file. In IPC communication mode, an IPC object can be shared by multiple processes through the use of "keys".
All data structures in the Linux system that represent IPC objects in System V include an ipc_perm structure that contains the key value of the IPC object, which is used to find the reference identifier of the IPC object in System V. Without keys, the process will not be able to access the IPC object because the IPC object does not exist in the memory used by the process itself.
Usually, you want your program to agree on a unique key value with other programs in advance, but it is not always possible, because your program cannot select a key value for a piece of shared memory. Therefore, set key to IPC_PRIVATE here, so that the operating system will ignore the key, create a new shared memory, specify a key value, and then return the shared memory IPC identifier ID. Instead, telling other processes the identifier ID of this new shared memory can be achieved by deriving child processes or writing to files or pipes after the shared memory is established.
Int size (unit byte Byte)
Size is the length of shared memory to be established. All memory allocation operations are in pages. So if a process requests only one byte of memory, the memory will also be allocated an entire page (the default size of a page on an i386 machine, PACE_SIZE=4096 bytes) so that the size of the newly created shared memory is actually the page size adjusted from the size parameter. That is, if the size is 1 to 4096, the actual requested shared memory size is 4K (one page); from 4097 to 8192, the actual requested shared memory size is 8K (two pages), and so on.
Int shmflg
Shmflg is mainly related to some logos. Valid ones include IPC_CREAT and IPC_EXCL, which are as functional as O_CREAT and O_EXCL of open ().
IPC_CREAT if shared memory does not exist, create a shared memory, otherwise open operation.
IPC_EXCL the new shared memory is created only when the shared memory does not exist, otherwise an error occurs.
If you use the IPC_CREAT,shmget () function alone, you can either return an operator of existing shared memory or an identifier of a newly created shared memory. If you use the IPC_CREAT with the IPC_EXCL flag, shmget () returns an identifier of the newly created shared memory, or-1 if the shared memory already exists. The IPC_EXEL flag itself doesn't make much sense, but used with the IPC_CREAT flag can be used to ensure that the resulting object is new, rather than opening an existing object. Specify SHM_R and SHM_W for the user's read and write licenses, (SHM_R > 3) and (SHM_W > 3) are a set of read and write licenses, and (SHM_R > 6) and (SHM_W > 6) are global read and write licenses.
Return value
Successfully returned the identifier of the shared memory; unsuccessfully returned-1 error reason for storing errno.
The EINVAL parameter size is less than SHMMIN or greater than SHMMAX.
EEXIST pre-establishes the shared memory caused by key, but already exists.
The shared memory caused by the EIDRM parameter key has been deleted.
The ENOSPC exceeds the maximum amount of shared memory allowed to be established by the system (SHMALL).
The shared memory referred to in the ENOENT parameter key does not exist, and the parameter shmflg does not have the IPC_CREAT bit set.
EACCES does not have permissions.
The ENOMEM core is out of memory.
Struct shmid_ds
The shmid_ds data structure represents each newly created shared memory. When shmget () creates a new piece of shared memory, it returns an identifier of the shmid_ds data structure that can be used to reference the shared memory.
Include/linux/shm.h
Struct shmid_ds {
Struct ipc_perm shm_perm; / * operation perms * /
Int shm_segsz; / * size of segment (bytes) * /
_ _ kernel_time_t shm_atime; / * last attach time * /
_ _ kernel_time_t shm_dtime; / * last detach time * /
_ _ kernel_time_t shm_ctime; / * last change time * /
_ _ kernel_ipc_pid_t shm_cpid; / * pid of creator * /
_ _ kernel_ipc_pid_t shm_lpid; / * pid of last operator * /
Unsigned short shm_nattch; / * no. Of current attaches * /
Unsigned short shm_unused; / * compatibility * /
Void * shm_unused2; / * ditto-used by DIPC * /
Void * shm_unused3; / * unused * /
}
Struct ipc_perm
For each IPC object, the system uses a data structure of struct ipc_perm to store permission information to determine whether an ipc operation can access the IPC object.
Struct ipc_perm {
_ _ kernel_key_t key
_ _ kernel_uid_t uid
_ _ kernel_gid_t gid
_ _ kernel_uid_t cuid
_ _ kernel_gid_t cgid
_ _ kernel_mode_t mode
Unsigned short seq
}; [@ more@]
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.