Copyright (C) 2000-2012 |
Manpages SHMOPSection: Linux Programmer's Manual (2)Updated: 1993-11-28 Index Return to Main Contents NAMEshmop - shared memory operationsSYNOPSIS# include <sys/types.h> # include <sys/shm.h> void *shmat ( int shmid, const void *shmaddr, int shmflg ) int shmdt ( const void *shmaddr) DESCRIPTIONThe function shmat attaches the shared memory segment identified by shmid to the data segment of the calling process. The attaching address is specified by shmaddr with one of the following criteria:
If SHM_RDONLY is asserted in shmflg, the segment is attached for reading and the process must have read access permissions to the segment. Otherwise the segment is attached for read and write and the process must have read and write access permissions to the segment. There is no notion of write-only shared memory segment. The brk value of the calling process is not altered by the attach. The segment will automatically detached at process exit. The same segment may be attached as a read and as a read-write one, and more than once, in the process's address space. On a successful shmat call the system updates the members of the structure shmid_ds associated to the shared memory segment as follows:
Note that the attach succeeds also if the shared memory segment is marked as to be deleted. The function shmdt detaches from the calling process's data segment the shared memory segment located at the address specified by shmaddr. The detaching shared memory segment must be one among the currently attached ones (to the process's address space) with shmaddr equal to the value returned by the its attaching shmat call. On a successful shmdt call the system updates the members of the structure shmid_ds associated to the shared memory segment as follows:
The occupied region in the user space of the calling process is unmapped. SYSTEM CALLS
RETURN VALUEOn a failure both functions return -1 with errno indicating the error, otherwise shmat returns the address of the attached shared memory segment, and shmdt returns 0.ERRORSWhen shmat fails, at return errno will be set to one among the following values:
The function shmdt can fails only if there is no shared memory segment attached at shmaddr, in such a case at return errno will be set to EINVAL. NOTESOn executing a fork(2) system call, the child inherits all the attached shared memory segments.The shared memory segments attached to a process executing an execve(2) system call will not be attached to the resulting process. The following is a system parameter affecting a shmat system call:
The implementation has no intrinsic limit to the per process maximum number of shared memory segments (SHMSEG) CONFORMING TOSVr4, SVID. SVr4 documents an additional error condition EMFILE. In SVID-v4 the type of the shmaddr argument was changed from char * into const void *, and the returned type of shmat() from char * into void *. (Linux libc4 and libc5 have the char * prototypes; glibc2 has void *.)SEE ALSOipc(5), shmctl(2), shmget(2)
IndexThis document was created by man2html, using the manual pages. Time: 01:18:28 GMT, January 21, 2025 |