shmget()

get shared memory identifier 

Function


SYNOPSIS

#include <sys/shm.h>

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


DESCRIPTION

The shmget() function returns the shared memory identifier associated with key. A shared memory identifier and shared memory segment of at least size bytes is created if key is equal to IPC_PRIVATE, or if key does not already have a shared memory identifier associated with it and if (shmflg & IPC_CREAT) is non-zero.

Upon creation, the internal attributes associated with the new shared memory identifier are initialized as follows:

You must explicitly remove shared memory segments after the last reference to them has been removed.

The ftok() function can be used to generate unique keys that can be passed as values for key.


PARAMETERS

key 

Specifies either IPC_PRIVATE or a unique key.

size 

Is the size in bytes of the shared memory segment.

shmflg 

Specifies both the creation and permission bits (for example, IPC_CREAT | 0666).


RETURN VALUES

If successful, shmget() returns a shared memory identifier. On failure, it returns -1 and sets errno to one of the following values:

EACCES 

A shared memory identifier exists for key but operation permission as specified by the permission bits of shmflg would not be granted.

EEXIST 

A shared memory identifier exists for key, but both (shmflg&IPC_CREAT) and (shmflg&IPC_EXCL) are non-zero.

EINVAL 

A shared memory identifier exists for key, but the size of the segment associated with it is less than size and size is not equal to zero.

size is less than the system-imposed minimum or greater than the system-imposed maximum.

ENOENT 

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

ENOMEM 

A shared memory identifier and associated shared memory segment are to be created, but the amount of available memory is not sufficient to fulfill the request.

ENOSPC 

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.


CONFORMANCE

UNIX 98.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

None.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
ftok(), shmat(), shmctl(), shmdt()


PTC MKS Toolkit 10.4 Documentation Build 39.