-.\" Hey Emacs! This file is -*- nroff -*- source.
-.\"
.\" Copyright (C) 2002 Michael Kerrisk <mtk.manpages@gmail.com>
.\"
+.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
+.\" %%%LICENSE_END
.\"
.\" FIXME . Add an example to this page
-.TH SHM_OPEN 3 2009-02-20 "Linux" "Linux Programmer's Manual"
+.TH SHM_OPEN 3 2017-09-15 "Linux" "Linux Programmer's Manual"
.SH NAME
-shm_open, shm_unlink \- Create/open or unlink POSIX shared memory objects
+shm_open, shm_unlink \- create/open or unlink POSIX shared memory objects
.SH SYNOPSIS
.B #include <sys/mman.h>
.br
.BR "#include <sys/stat.h>" " /* For mode constants */"
.br
.BR "#include <fcntl.h>" " /* For O_* constants */"
-.sp
+.PP
.BI "int shm_open(const char *" name ", int " oflag ", mode_t " mode );
-.sp
+.PP
.BI "int shm_unlink(const char *" name );
-.sp
+.PP
Link with \fI\-lrt\fP.
.SH DESCRIPTION
.BR shm_open ()
function performs the converse operation,
removing an object previously created by
.BR shm_open ().
-.LP
+.PP
The operation of
.BR shm_open ()
is analogous to that of
a shared memory object should be identified by a name of the form
.IR /somename ;
that is, a null-terminated string of up to
-.BI NAME_MAX +1
-(i.e., 256) characters consisting of an initial slash,
+.BI NAME_MAX
+(i.e., 255) characters consisting of an initial slash,
.\" glibc allows the initial slash to be omitted, and makes
.\" multiple initial slashes equivalent to a single slash.
.\" This differs from the implementation of POSIX message queues.
.\" case the subdirectory must exist under /dev/shm, and allow the
.\" required permissions if a user wants to create a shared memory
.\" object in that subdirectory.
-.LP
+.PP
.I oflag
is a bit mask created by ORing together exactly one of
.B O_RDONLY
.TP 1.1i
.B O_RDONLY
Open the object for read access.
-A shared memory object opened in this way can only be
+A shared memory object opened in this way can be
.BR mmap (2)ed
-for read (\fBPROT_READ\fP) access.
+only for read
+.RB ( PROT_READ )
+access.
.TP
.B O_RDWR
Open the object for read-write access.
Create the shared memory object if it does not exist.
The user and group ownership of the object are taken
from the corresponding effective IDs of the calling process,
-.\" In truth it is actually the file system IDs on Linux, but these
+.\" In truth it is actually the filesystem IDs on Linux, but these
.\" are nearly always the same as the effective IDs. (MTK, Jul 05)
and the object's
permission bits are set according to the low-order 9 bits of
.BR open (2).
(Symbolic definitions of these constants can be obtained by including
.IR <sys/stat.h> .)
-.sp
-A new shared memory object initially has zero length \(em the size of the
+.IP
+A new shared memory object initially has zero length\(emthe size of the
object can be set using
.BR ftruncate (2).
The newly allocated bytes of a shared memory
.TP
.B O_TRUNC
If the shared memory object already exists, truncate it to zero bytes.
-.LP
+.PP
Definitions of these flag values can be obtained by including
.IR <fcntl.h> .
-.LP
+.PP
On successful completion
.BR shm_open ()
returns a new file descriptor referring to the shared memory object.
flag (see
.BR fcntl (2))
is set for the file descriptor.
-
+.PP
The file descriptor is normally used in subsequent calls
to
.BR ftruncate (2)
After a call to
.BR mmap (2)
the file descriptor may be closed without affecting the memory mapping.
-
+.PP
The operation
of
.BR shm_unlink ()
.BR shm_open ()
an object with the same
.I name
-will fail (unless
+fail (unless
.B O_CREAT
was specified, in which case a new, distinct object is created).
-.SH "RETURN VALUE"
+.SH RETURN VALUE
On success,
.BR shm_open ()
-returns a non-negative file descriptor.
+returns a nonnegative file descriptor.
On failure,
.BR shm_open ()
returns \-1.
was invalid.
.TP
.B EMFILE
-The process already has the maximum number of files open.
+The per-process limit on the number of open file descriptors has been reached.
.TP
.B ENAMETOOLONG
The length of
.BR PATH_MAX .
.TP
.B ENFILE
-The limit on the total number of files open on the system has been
-reached.
+The system-wide limit on the total number of open files has been reached.
.TP
.B ENOENT
An attempt was made to
that does not exist.
.SH VERSIONS
These functions are provided in glibc 2.2 and later.
-.SH "CONFORMING TO"
-POSIX.1-2001.
-.LP
+.SH ATTRIBUTES
+For an explanation of the terms used in this section, see
+.BR attributes (7).
+.TS
+allbox;
+lbw24 lb lb
+l l l.
+Interface Attribute Value
+T{
+.BR shm_open (),
+.BR shm_unlink ()
+T} Thread safety MT-Safe locale
+.TE
+.sp 1
+.SH CONFORMING TO
+POSIX.1-2001, POSIX.1-2008.
+.PP
POSIX.1-2001 says that the group ownership of a newly created shared
memory object is set to either the calling process's effective group ID
or "a system default group ID".
-.SH "NOTES"
-.LP
+POSIX.1-2008 says that the group ownership
+may be set to either the calling process's effective group ID
+or, if the object is visible in the filesystem,
+the group ID of the parent directory.
+.SH NOTES
+.PP
POSIX leaves the behavior of the combination of
.B O_RDONLY
and
.B O_TRUNC
unspecified.
On Linux, this will successfully truncate an existing
-shared memory object \(em this may not be so on other Unix systems.
-.LP
-The POSIX shared memory object implementation on Linux 2.4 makes use
-of a dedicated file system, which is normally
-mounted under
+shared memory object\(emthis may not be so on other UNIX systems.
+.PP
+The POSIX shared memory object implementation on Linux makes use
+of a dedicated
+.BR tmpfs (5)
+filesystem that is normally mounted under
.IR /dev/shm .
-.SH "SEE ALSO"
+.SH SEE ALSO
.BR close (2),
.BR fchmod (2),
.BR fchown (2),
.BR fcntl (2),
.BR fstat (2),
.BR ftruncate (2),
+.BR memfd_create (2),
.BR mmap (2),
.BR open (2),
.BR umask (2),