shm_open(2) 맨 페이지 - 윈디하나의 솔라나라

개요

섹션
맨 페이지 이름
검색(S)

shm_open(2)

The system call opens (or optionally creates) a shared memory ob‐
ject named The argument contains a subset of the flags used by An
access  mode  of either or must be included in The optional flags
and may also be specified.  If is specified, then  a  new  shared
memory  object  named  will  be created if it does not exist.  In
this case, the shared memory object is created with mode  subject
to the process' umask value.  If both the and flags are specified
and  a  shared memory object named already exists, then will fail
with Newly created objects start off with a size of zero.  If  an
existing  shared  memory  object  is  opened with and the flag is
specified, then the shared memory object will be truncated  to  a
size  of  zero.   The  size of the object can be adjusted via and
queried via The new descriptor is  set  to  close  during  system
calls;  see  and As a FreeBSD extension, the constant may be used
for the argument to In this case, an  anonymous,  unnamed  shared
memory  object is created.  Since the object has no name, it can‐
not be removed via a subsequent call to Instead, the shared  mem‐
ory  object  will be garbage collected when the last reference to
the shared memory object is removed.  The  shared  memory  object
may be shared with other processes by sharing the file descriptor
via  or Attempting to open an anonymous shared memory object with
will fail with All other flags are ignored.  The system call  re‐
moves  a shared memory object named If successful, returns a non-
negative integer, and returns zero.  Both functions return -1  on
failure,  and  set  to indicate the error.  The argument does not
necessarily represent a pathname (although it does in most  other
implementations).   Two processes opening the same are guaranteed
to access the same shared memory object if  and  only  if  begins
with  a  slash  character.   Only  the  and  flags may be used in
portable programs.  specifications state that the result of using
or on a shared memory object, or on the descriptor returned by is
undefined.  However, the  kernel  implementation  explicitly  in‐
cludes  support  for  and also supports zero-copy transmission of
data from shared memory objects with Neither  shared  memory  ob‐
jects  nor  their contents persist across reboots.  Writes do not
extend shared memory objects, so must be called before  any  data
can be written.  See This example fails without the call to

        uint8_t buffer[getpagesize()];
        ssize_t len;
        int fd;

        fd = shm_open(SHM_ANON, O_RDWR | O_CREAT, 0600);
        if (fd < 0)
                err(EX_OSERR, "%s: shm_open", __func__);
        if (ftruncate(fd, getpagesize()) < 0)
                err(EX_IOERR, "%s: ftruncate", __func__);
        len = pwrite(fd, buffer, getpagesize(), 0);
        if (len < 0)
                err(EX_IOERR, "%s: pwrite", __func__);
        if (len != getpagesize())
                errx(EX_IOERR,   "%s:  pwrite  length  mismatch",
__func__); fails with these error codes for these  conditions:  A
flag  other  than  or  was  included  in  The process has already
reached its limit for open file descriptors.  The system file ta‐
ble is full.  was specified while creating  an  anonymous  shared
memory  object via The argument points outside the process' allo‐
cated address space.  The entire pathname exceeded  1023  charac‐
ters.   The  does not begin with a slash character.  is specified
and the named shared memory object does not exist.  and are spec‐
ified and the named shared memory object  does  exist.   The  re‐
quired  permissions  (for reading or reading and writing) are de‐
nied.  fails with these error codes for these conditions: The ar‐
gument points outside the process' allocated address space.   The
entire  pathname exceeded 1023 characters.  The named shared mem‐
ory object does not exist.  The required permissions are  denied.
requires  write  permission to the shared memory object.  The and
functions are believed to conform to The and functions first  ap‐
peared  in The functions were reimplemented as system calls using
shared memory objects directly rather than files  in  (C  library
support and this manual page)





























































맨 페이지 내용의 저작권은 맨 페이지 작성자에게 있습니다.
RSS ATOM XHTML 5 CSS3