shm_open()

open a shared memory object (REALTIME) 

Realtime Function


SYNOPSIS

#include <sys/mman.h>

int shm_open(const char *name, int oflag, mode_t mode);


DESCRIPTION

The shm_open() function establishes a connection between a shared memory object and a file descriptor. It creates an open file description that refers to the shared memory object and a file descriptor that refers to that open file description. The file descriptor created can be used by other functions to refer to that shared memory object. The name argument points to a string naming a shared memory object. The name argument must begin with the slash character. Processes calling shm_open() with the same value of name refer to the same shared memory object, as long as that name has not been removed.

When successful, shm_open() returns a file descriptor for the shared memory object that is the lowest numbered file descriptor not currently open for that process. The open file description is new, and therefore the file descriptor does not share it with any other processes. The FD_CLOEXEC file descriptor flag associated with the new file descriptor is set.

The file status flags and file access modes of the open file description are set according to the value of oflag. The oflag argument is the bitwise-inclusive OR of the following flags defined in the <fcntl.h> header. Applications specify exactly one of the first two values (access modes) below in the value of oflag:

O_RDONLY 

Open for read access only.

O_RDWR 

Open for read or write access.

Any combination of the remaining flags may be specified in the value of oflag:

O_CREAT 

When the shared memory object exists, this flag has no effect, except as noted under O_EXCL below. Otherwise, the shared memory object is created; the user ID of the shared memory object is set to the effective user ID of the process; the group ID of the shared memory object is set to a system default group ID or to the effective group ID of the process. The permission bits of the shared memory object are set to the value of the mode argument except those set in the file mode creation mask of the process. The mode argument does not affect whether the shared memory object is opened for reading, for writing, or for both. The shared memory object has a size of zero.

O_EXCL 

When O_EXCL and O_CREAT are set, shm_open() fails if the shared memory object exists. The check for the existence of the shared memory object and the creation of the object if it does not exist is atomic with respect to other processes executing shm_open() naming the same shared memory object with O_EXCL and O_CREAT set.

O_TRUNC 

When the shared memory object exists, and it is successfully opened O_RDWR, the object is truncated to zero length and the mode and owner is unchanged by this function call.

When a shared memory object is created, the state of the shared memory object, including all data associated with the shared memory object, persists until the shared memory object is unlinked and all other references are gone.


PARAMETERS

mode 

Specifies the values to be set for the permission bits of the created shared memory object.

name 

Points to the name to be assigned to the created shared memory object.

oflag 

Specifies the file status flags and file access modes to be used with the open file description .


RETURN VALUES

On success, the shm_open() function returns a non-negative integer representing the lowest numbered unused file descriptor. On failure, it returns -1 and sets errno to one of the following:

EACCES 

The shared memory object exists and the permissions specified by oflag are denied, or the shared memory object does not exist and permission to create the shared memory object is denied, or O_TRUNC is specified and write permission is denied.

EEXIST 

O_CREAT and O_EXCL are set and the named shared memory object already exists.

EINTR 

The shm_open() operation was interrupted by a signal.

EINVAL 

The shm_open() operation is not supported for the given name.

EMFILE 

Too many file descriptors are currently in use by this process.

ENAMETOOLONG 

The name argument is too long.

ENFILE 

Too many shared memory objects are currently open in the system.

ENOENT 

O_CREAT is not set and the named shared memory object does not exist.

ENOSPC 

There is insufficient space for the creation of the new shared memory object.


CONFORMANCE

UNIX 03.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

When compiling programs that use this function, you must specify the -lrt option to cc or ld to ensure linking against the correct library.


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:
close(), dup(), exec(), fcntl(), mmap(), shm_unlink(), shmat(), shmctl(), shmdt(), umask()


PTC MKS Toolkit 10.3 Documentation Build 39.