Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

shmget - create shared memory segment

&pagelevel(4)&pagelevel

Syntax

#include <sys/shm.h>

int shmget(key_t key, int size, int shmflg);

Description

shmget() returns the shared memory identifier associated with key.

A shared memory identifier, associated data structure and shared memory segment of at least size bytes (see sys/shm.h) are created for key if one of the following conditions is true:

  • The argument key has the value IPC_PRIVATE.

  • The argument key does not already have a shared memory identifier associated with it and (shmflg & IPC_CREAT) is not equal to 0.

Upon creation, the data structure associated with the new shared memory identifier is initialized as follows:

  • The values of shm_perm.cuid, shm_perm.uid, shm_perm.cgid and shm_perm.gid are set to the effective user/group ID of the calling process.

  • The 9 low-order bits of shm_perm.mode are set equal to the 9 low-order bits of shmflg.
    The argument shm_segsz is set to the value of size.

  • The values of shm_lpid, shm_nattch, shm_atime and shm_dtime are set equal to 0.

  • The current time is entered for shm_ctime.

Return val.

Shared memory identifier


if successful. The shared memory ID is a non-negative integer.

-1

if an error occurs. errno is set to indicate the error.

Errors

shmget() will fail if:


EACCES

A shared memory ID for the argument key exists, but the permissions specified in the 9 low-order bits of shmflg were not granted.

 

EEXIST

A shared memory ID exists for the argument key, but ((shmflg & IPC_CREAT) && (shmflg & IPC_EXCL)) is not equal to 0.

 

EINVAL

The value of size is less than the system-imposed minimum or greater than the system-imposed maximum, or a shared memory identifier exists for the argument key, but the size of the segment associated with it is less than size and size is not 0.

 

ENOENT

A shared memory identifier does not exist for key and (shmflg & IPC_CREAT) is 0.


ENOMEM

The amount of available physical memory is not sufficient to fill the request.


ENOSPC

The system-imposed limit on the maximum number of allowed shared memory IDs would be exceeded.

Note

BS2000
Tasks with only read permission are not prevented from writing to the shared memory area using BS2000 resources. (End)

See also

shmat(), shmctl(), shmdt(), sys/shm.h, section “Interprocess communication”.