Page 852 time_t shm_atime; /* last attach time */ time_t shm_dtime; /* last detach time */ time_t shm_ctime; /* last change time */ unsigned short shm_cpid; /* pid of creator */ unsigned short shm_lpid; /* pid of last operator */ short shm_nattch; /* no. of current attaches */ }; struct ipc_perm { key_t key; ushort uid; /* owner euid and egid */ ushort gid; ushort cuid; /* creator euid and egid */ ushort cgid; ushort mode; /* lower 9 bits of shmflg */ ushort seq; /* sequence number */ }; Furthermore, while creating, the system call initializes the system shared memory segment data structure shmid_ds as follows:
If the shared memory segment already exists, the access permissions are verified, and a check is made to see if it is marked for destruction. System Calls
RETURN VALUE A valid segment identifier, shmid, is returned on success, _1 on error. ERRORS On failure, errno is set to one of the following:
Page 853 NOTES IPC_PRIVATE isn't a flag field but a key_t type. If this special value is used for key, the system call ignores everything but the lowest order 9 bits of shmflg and creates a new shared memory segment (on success). The following are limits on shared memory segment resources affecting a shmget call:
The implementation has no specific limits for the per-process maximum number of shared memory segments (SHMSEG). BUGS Use of IPC_PRIVATE does not inhibit other processes' access to the allocated shared memory segment. As for the files, there is currently no intrinsic way for a process to ensure exclusive access to a shared memory segment. Asserting both IPC_CREAT and IPC_EXCL in shmflg only ensures (on success) that a new shared memory segment will be created; it doesn't imply exclusive access to the segment. SEE ALSO ftok(3), ipc(5), shmctl(2), shmat(2), shmdt(2) Linux 0.99.11, 28 November 1993 shmopshmopShared memory operations SYPNOSIS #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> char *shmat ( int shmid, char *shmaddr, int shmflg ); int shmdt ( char *shmaddr); DESCRIPTION The 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 a write-only shared memory segment. The brk value of the calling process is not altered by the attach. The segment will automatically be detached at process exit. The same segment may be attached as a read and as a read-write segment, more than once, in the process's address space. Page 854 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 attachment will also succeed if the shared memory segment is marked 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 its attaching shat 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 VALUE On 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. ERRORS When shmat fails, at return errno will be set to one of the following values:
The function shmdt can fail only if there is no shared memory segment attached at shmaddr; in such a case, errno will be set to EINVAL at return. NOTES On executing a fork(2) system call, the child inherits all the attached shared memory segments. The shared memory segments attached to a process executing anexec(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) SEE ALSO ipc(5), shmctl(2), shmget(2) Linux 0.99.13, 28 November 1993 |