summaryrefslogtreecommitdiffstats
path: root/man3/shm_open.3
diff options
context:
space:
mode:
Diffstat (limited to 'man3/shm_open.3')
-rw-r--r--man3/shm_open.3121
1 files changed, 60 insertions, 61 deletions
diff --git a/man3/shm_open.3 b/man3/shm_open.3
index 24eddb027..c5756c475 100644
--- a/man3/shm_open.3
+++ b/man3/shm_open.3
@@ -3,7 +3,7 @@
.\"
.\" SPDX-License-Identifier: Linux-man-pages-copyleft
.\"
-.TH shm_open 3 2023-02-05 "Linux man-pages 6.03"
+.TH shm_open 3 2023-07-20 "Linux man-pages 6.05.01"
.SH NAME
shm_open, shm_unlink \- create/open or unlink POSIX shared memory objects
.SH LIBRARY
@@ -220,37 +220,23 @@ An attempt was to made to
a
.I name
that does not exist.
-.SH VERSIONS
-These functions are provided in glibc 2.2 and later.
.SH ATTRIBUTES
For an explanation of the terms used in this section, see
.BR attributes (7).
-.ad l
-.nh
.TS
allbox;
lbx lb lb
l l l.
Interface Attribute Value
T{
+.na
+.nh
.BR shm_open (),
.BR shm_unlink ()
T} Thread safety MT-Safe locale
.TE
-.hy
-.ad
.sp 1
-.SH STANDARDS
-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".
-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
+.SH VERSIONS
POSIX leaves the behavior of the combination of
.B O_RDONLY
and
@@ -264,6 +250,19 @@ of a dedicated
.BR tmpfs (5)
filesystem that is normally mounted under
.IR /dev/shm .
+.SH STANDARDS
+POSIX.1-2008.
+.SH HISTORY
+glibc 2.2.
+POSIX.1-2001.
+.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".
+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 EXAMPLES
The programs below employ POSIX shared memory and POSIX unnamed semaphores
to exchange a piece of data.
@@ -299,15 +298,15 @@ on the memory object that is shared between the two programs.
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
-
+\&
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
} while (0)
-
+\&
#define BUF_SIZE 1024 /* Maximum size for exchanged string */
-
+\&
/* Define a structure that will be imposed on the shared
memory object */
-
+\&
struct shmbuf {
sem_t sem1; /* POSIX unnamed semaphore */
sem_t sem2; /* POSIX unnamed semaphore */
@@ -336,74 +335,74 @@ to tell the "send" program that it may now access the shared memory.
.\" SRC BEGIN (pshm_ucase_bounce.c)
.EX
/* pshm_ucase_bounce.c
-
+\&
Licensed under GNU General Public License v2 or later.
*/
#include <ctype.h>
-
+\&
#include "pshm_ucase.h"
-
+\&
int
main(int argc, char *argv[])
{
int fd;
char *shmpath;
struct shmbuf *shmp;
-
+\&
if (argc != 2) {
fprintf(stderr, "Usage: %s /shm\-path\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
shmpath = argv[1];
-
+\&
/* Create shared memory object and set its size to the size
of our structure. */
-
+\&
fd = shm_open(shmpath, O_CREAT | O_EXCL | O_RDWR, 0600);
if (fd == \-1)
errExit("shm_open");
-
+\&
if (ftruncate(fd, sizeof(struct shmbuf)) == \-1)
errExit("ftruncate");
-
+\&
/* Map the object into the caller\[aq]s address space. */
-
+\&
shmp = mmap(NULL, sizeof(*shmp), PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
if (shmp == MAP_FAILED)
errExit("mmap");
-
+\&
/* Initialize semaphores as process\-shared, with value 0. */
-
+\&
if (sem_init(&shmp\->sem1, 1, 0) == \-1)
errExit("sem_init\-sem1");
if (sem_init(&shmp\->sem2, 1, 0) == \-1)
errExit("sem_init\-sem2");
-
+\&
/* Wait for \[aq]sem1\[aq] to be posted by peer before touching
shared memory. */
-
+\&
if (sem_wait(&shmp\->sem1) == \-1)
errExit("sem_wait");
-
+\&
/* Convert data in shared memory into upper case. */
-
+\&
for (size_t j = 0; j < shmp\->cnt; j++)
shmp\->buf[j] = toupper((unsigned char) shmp\->buf[j]);
-
+\&
/* Post \[aq]sem2\[aq] to tell the peer that it can now
access the modified data in shared memory. */
-
+\&
if (sem_post(&shmp\->sem2) == \-1)
errExit("sem_post");
-
+\&
/* Unlink the shared memory object. Even if the peer process
is still using the object, this is okay. The object will
be removed only after all open references are closed. */
-
+\&
shm_unlink(shmpath);
-
+\&
exit(EXIT_SUCCESS);
}
.EE
@@ -429,13 +428,13 @@ on standard output.
.\" SRC BEGIN (pshm_ucase_send.c)
.EX
/* pshm_ucase_send.c
-
+\&
Licensed under GNU General Public License v2 or later.
*/
#include <string.h>
-
+\&
#include "pshm_ucase.h"
-
+\&
int
main(int argc, char *argv[])
{
@@ -443,54 +442,54 @@ main(int argc, char *argv[])
char *shmpath, *string;
size_t len;
struct shmbuf *shmp;
-
+\&
if (argc != 3) {
fprintf(stderr, "Usage: %s /shm\-path string\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
shmpath = argv[1];
string = argv[2];
len = strlen(string);
-
+\&
if (len > BUF_SIZE) {
fprintf(stderr, "String is too long\en");
exit(EXIT_FAILURE);
}
-
+\&
/* Open the existing shared memory object and map it
into the caller\[aq]s address space. */
-
+\&
fd = shm_open(shmpath, O_RDWR, 0);
if (fd == \-1)
errExit("shm_open");
-
+\&
shmp = mmap(NULL, sizeof(*shmp), PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
if (shmp == MAP_FAILED)
errExit("mmap");
-
+\&
/* Copy data into the shared memory object. */
-
+\&
shmp\->cnt = len;
memcpy(&shmp\->buf, string, len);
-
+\&
/* Tell peer that it can now access shared memory. */
-
+\&
if (sem_post(&shmp\->sem1) == \-1)
errExit("sem_post");
-
+\&
/* Wait until peer says that it has finished accessing
the shared memory. */
-
+\&
if (sem_wait(&shmp\->sem2) == \-1)
errExit("sem_wait");
-
+\&
/* Write modified data in shared memory to standard output. */
-
+\&
write(STDOUT_FILENO, &shmp\->buf, len);
write(STDOUT_FILENO, "\en", 1);
-
+\&
exit(EXIT_SUCCESS);
}
.EE