#include <sys/shm.h> #include <sys/stat.h> int shmget(key_t key,size_t size, int shmflg);
|
The shmget() function returns the shared memory ID associated with the specified shared memory key.
Parameters
The value of the shmflg parameter is either zero or is obtained by performing an OR operation on one or more of the constants listed below. If an existing shared memory ID is being accessed, then the permissions specified must be a subset of the existing permissions of the shared memory segment. If an existing shared memory ID is being accessed, then the SHM_TS_NP and SHM_MAP_FIXED_NP flags must match the existing attributes of the shared memory segment.
Authorities
Figure 1-17. Authorization Required for shmget()
| Object Referred to | Authority Required | errno |
|---|---|---|
| Shared memory segment to be created | None | None |
| Existing shared memory segment to be accessed | See Note | EACCES |
| Note: If the thread is accessing a shared memory segment that already exists, the mode specified in the last 9 bits of shmflg must be a subset of the mode of the existing shared memory segment. |
Return Value
Error Conditions
If shmget() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
An attempt was made to access an object in a way forbidden by its object access permissions.
The thread does not have access to the specified file, directory, component, or path.
A shared memory identifier exists for the parameter key, but operation permission as specified by the low-order 9 bits of shmflg would not be granted.
The value of key corresponds to shared memory that has been marked as damaged by a previous shared memory operation.
The file specified already exists and the specified operation requires that it not exist.
The named file, directory, or path already exists.
A shared memory identifier exists for the parameter key, but ((shmflg & IPC_CREAT) && (shmflg & IPC_EXCL)) is not zero. (& is a bitwise AND; && is a logical AND.)
A function was passed incorrect argument values, or an operation was attempted on an object and the operation specified is not supported for that type of object.
An argument value is not valid, out of range, or NULL.
One of the following has occurred:
The directory or a component of the path name specified does not exist.
A named file or directory does not exist or is an empty string.
A shared memory identifier does not exist for the parameter key, and (shmflg & IPC_CREAT) is zero.
A function needed to allocate storage, but no storage is available.
A shared memory identifier and associated shared memory segment are to be created, but the amount of available physical memory is not sufficient to fulfill the request.
The requested operations required additional space on the device and there is no space left. This could also be caused by exceeding the user profile storage limit when creating or transferring ownership of an object.
Insufficient space remains to hold the intended file, directory, or link.
A shared memory identifier is to be created, but the system-imposed limit on the maximum number of allowed shared memory identifiers system-wide would be exceeded.
The operation failed because of an unknown system state. See any messages in the job log and correct any errors that are indicated, then retry the operation.
Error Messages
None.
Usage Notes
Related Information
Example
For an example of using this function, see Using Semaphores and Shared Memory in Appendix A, Examples.
| Top | Interprocess Communication APIs | APIs by category |
| [Information Center Home Page | Feedback ] | [Legal | AS/400 Glossary] |