Your Browser is not longer supported
Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...
{{viewport.spaceProperty.prod}}
shmat - shared memory attach operation
&pagelevel(4)&pagelevel
Syntax | #include <sys/shm.h> void *shmat(int shmid, const void *shmaddr, int shmflg); |
Description | shmat() attaches the shared memory segment designated by the shared memory identifier shmid to the data segment of the calling process. The location at which the segment is attached is determined by the following criteria:
If shmaddr is equal to 0, the segment is attached at the first free address found by the system. If shmaddr and (shmflg & SHM_RND ) are not equal to 0, the segment is attached at the address given by (shmaddr -((ptrdiff_t) shmaddr % SHMLBA) ). (The character % is the C-language remainder operator.) If shmaddr is not equal to 0 and (shmflg & SHM_RND ) is equal to 0, the segment is attached at the address specified with shmaddr. If (shmflg & SHM_RDONLY ) is not equal to 0 and the calling process has read permission, the segment is attached for reading. If (shmflg & SHM_RDONLY ) is not equal to 0 and the calling process has read and write permission, the segment is attached for reading and writing.
The following symbolic names are defined in the header file sys/shm.h : Name | Description | SHMLBA
| Multiple of the address of the lower segment boundary | SHM_RDONLY
| Attach only for reading | SHM_RND
| Round up attachment address |
|
Return val. | Start address of the data segment for the shared memory area |
|
| if successful. The value of shm_nattach is incremented in the data structure associated with the shared memory ID. |
| -1 | if an error occurs. The shared memory segment is not attached. errno is set to indicate the error. |
Errors | shmat() will fail if:
|
| EACCES
| The calling process is denied the access permissions required for the operation. |
| EINVAL
| The value of shmid is not a valid shared memory ID, or the value of shmaddr is not equal to 0 and the value of (shmaddr -((ptrdiff_t ) shmaddr % SHMLBA) ) is an invalid address for attaching shared memory, or the value of shmaddr is not equal to 0, (shmflg & SHM_RND ) is equal to 0 and the value of shmaddr is an invalid address for attaching shared memory. |
| EMFILE
| The number of attached shared memory segments for the calling process would exceed the system-imposed limit. |
| ENOMEM
| The available data space is not large enough to accommodate the shared memory segment. |
Notes | The IEEE 1003.4 Standards Committee is developing alternative interfaces for interprocess communication. Application developers who need to use interprocess communication (IPC) should design their applications so that modules using the IPC routines described here can be easily modified at a later date. |
See also | exec , exit() , fork() , shmctl() , shmdt() , shmget() , sys/shm.h , section “Interprocess communication”.
|