| Skip Navigation Links | |
| Exit Print View | |
![]() | man pages section 2: System Calls Oracle Solaris 11 Information Library |
- shared memory operations
#include <sys/types.h>#include <sys/shm.h>void *shmat(intshmid,const void *shmaddr,intshmflg);
intshmdt(const void *shmaddr);
Theshmat() function attaches the shared memory segment associated with the sharedmemory identifier specified byshmid to the data segment of the callingprocess.
The permission required for a shared memory control operation is given as{token}, wheretoken is the type of permission needed. The types ofpermission are interpreted as follows:
00400 READ by user00200 WRITE by user00040 READ by group00020 WRITE by group00004 READ by others00002 WRITE by others
See theShared Memory Operation Permissions section ofIntro(2) for more information.
For shared memory segments created with theSHM_SHARE_MMU orSHM_PAGEABLE flags, thedefault protections cannot be changed so as to prevent a single processfrom affecting other processes sharing the same shared segment.
When (shmflg&SHM_SHARE_MMU) is true, virtual memory resources in addition to shared memoryitself are shared among processes that use the same shared memory.
When (shmflg&SHM_PAGEABLE) is true, virtual memory resources are shared and the dynamicshared memory (DISM) framework is created. The dynamic shared memory can beresized dynamically within the specified size inshmget(2). The DISM shared memoryis pageable unless it is locked.
The shared memory segment is attached to the data segment of thecalling process at the address specified based on one of the following criteria:
Ifshmaddr is equal to(void *) 0, the segment is attached to the first available address as selected by the system.
Ifshmaddr is equal to(void*)0 and (shmflg&SHM_SHARE_MMU) or (shmflg&SHM_PAGEABLE) is true, then the segment is attached to the first available suitably aligned address. When (shmflg&SHM_SHARE_MMU) or (shmflg&SHM_PAGEABLE) is set, however, the permission given byshmget() determines whether the segment is attached for reading or reading and writing.
Ifshmaddr is not equal to(void *) 0 and (shmflg&SHM_RND) is true, the segment is attached to the address given by (shmaddr- (shmaddr modulusSHMLBA)).
Ifshmaddr is not equal to(void *) 0 and (shmflg&SHM_RND) is false, the segment is attached to the address given byshmaddr.
The segment is attached for reading if (shmflg&SHM_RDONLY) is true {READ}, otherwise it is attached for reading and writing {READ/WRITE}.
Theshmdt() function detaches from the calling process's data segment the sharedmemory segment located at the address specified byshmaddr.
Shared memory segments must be explicitly removed after the last reference tothem has been removed.
Upon successful completion,shmat() returns the data segment start address of theattached shared memory segment;shmdt() returns0. Otherwise,-1 is returned, theshared memory segment is not attached, anderrno is set to indicatethe error.
Theshmat() function will fail if:
Operation permission is denied to the calling process (seeIntro(2)).
Theshmid argument is not a valid shared memory identifier.
Theshmaddr argument is not equal to 0, and the value of (shmaddr- (shmaddr modulusSHMLBA)) is an illegal address.
Theshmaddr argument is not equal to 0, is an illegal address, and (shmflg&SHM_RND) is false.
Theshmaddr argument is not equal to 0, is not properly aligned, and (shmfg&SHM_SHARE_MMU) is true.
SHM_SHARE_MMU is not supported in certain architectures.
Both (shmflg&SHM_SHARE_MMU) and(shmflg&SHM_PAGEABLE) are true.
(shmflg&SHM_SHARE_MMU) is true and the shared memory segment specified byshmid() had previously been attached by a call toshmat() in which (shmflg&SHM_PAGEABLE) was true.
(shmflg&SHM_PAGEABLE) is true and the shared memory segment specified byshmid() had previously been attached by a call toshmat() in which (shmflg&SHM_SHARE_MMU) was true.
The number of shared memory segments attached to the calling process would exceed the system-imposed limit.
The available data space is not large enough to accommodate the shared memory segment.
Theshmdt() function will fail if:
Theshmaddr argument is not the data segment start address of a shared memory segment.
(shmflg&SHM_SHARE_MMU) is true and attaching to the shared memory segment would exceed a limit or resource control on locked memory.
Using a fixed value for theshmaddr argument can adversely affect performanceon certain platforms due to D-cache aliasing.
Seeattributes(5) for descriptions of the following attributes:
|
Intro(2),exec(2),exit(2),fork(2),shmctl(2),shmget(2),attributes(5),standards(5)
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |