OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man2 / shmop.2
index db5555e..33ce8bd 100644 (file)
 .\"            of segments marked for destruction
 .\"
 .\" FIXME . Add an example program to this page.
-.\" FIXME Linux 2.6.9 added SHM_EXEC, which should be documented
-.TH SHMOP 2 2013-02-12 "Linux" "Linux Programmer's Manual"
+.\"
+.TH SHMOP 2 2014-07-08 "Linux" "Linux Programmer's Manual"
 .SH NAME
-shmat, shmdt \- shared memory operations
+shmat, shmdt \- System V shared memory operations
 .SH SYNOPSIS
 .nf
 .B #include <sys/types.h>
@@ -51,20 +51,21 @@ shmat, shmdt \- shared memory operations
 .BI "int shmdt(const void *" shmaddr );
 .fi
 .SH DESCRIPTION
+.SS shmat()
 .BR shmat ()
-attaches the shared memory segment identified by
+attaches the System\ V shared memory segment identified by
 .I shmid
 to the address space of the calling process.
 The attaching address is specified by
 .I shmaddr
 with one of the following criteria:
-.LP
+.IP * 3
 If
 .I shmaddr
 is NULL,
 the system chooses a suitable (unused) address at which to attach
 the segment.
-.LP
+.IP *
 If
 .I shmaddr
 isn't NULL
@@ -76,29 +77,36 @@ the attach occurs at the address equal to
 .I shmaddr
 rounded down to the nearest multiple of
 .BR SHMLBA .
-Otherwise
+.IP *
+Otherwise,
 .I shmaddr
 must be a page-aligned address at which the attach occurs.
 .PP
-If
-.B SHM_RDONLY
-is specified in
-.IR shmflg ,
-the segment is attached for reading and the process must have
-read permission for the segment.
-Otherwise the segment is attached for read and write
+In addition to
+.BR SHM_RND ,
+the following flags may be specified in the
+.I shmflg
+bit-mask argument:
+.TP
+.BR SHM_EXEC " (Linux-specific; since Linux 2.6.9)"
+Allow the contents of the segment to be executed.
+The caller must have execute permission on the segment.
+.TP
+.BR SHM_RDONLY
+Attach the segment for read-only access.
+The process must have read permission for the segment.
+If this flag is not specified,
+the segment is attached for read and write access,
 and the process must have read and write permission for the segment.
 There is no notion of a write-only shared memory segment.
-.PP
-The (Linux-specific)
-.B SHM_REMAP
-flag may be specified in
-.I shmflg
-to indicate that the mapping of the segment should replace
+.TP
+.BR SHM_REMAP " (Linux-specific)"
+This flag specifies
+that the mapping of the segment should replace
 any existing mapping in the range starting at
 .I shmaddr
 and continuing for the size of the segment.
-(Normally an
+(Normally, an
 .B EINVAL
 error would result if a mapping already exists in this address range.)
 In this case,
@@ -128,7 +136,8 @@ is set to the process-ID of the calling process.
 .IP
 .I shm_nattch
 is incremented by one.
-.PP
+.\"
+.SS shmdt()
 .BR shmdt ()
 detaches the shared memory segment located at the address specified by
 .I shmaddr
@@ -142,7 +151,7 @@ call.
 .PP
 On a successful
 .BR shmdt ()
-call the system updates the members of the
+call, the system updates the members of the
 .I shmid_ds
 structure associated with the shared memory segment as follows:
 .IP
@@ -156,28 +165,16 @@ is set to the process-ID of the calling process.
 is decremented by one.
 If it becomes 0 and the segment is marked for deletion,
 the segment is deleted.
-.PP
-After a
-.BR fork (2)
-the child inherits the attached shared memory segments.
-
-After an
-.BR execve (2)
-all attached shared memory segments are detached from the process.
-
-Upon
-.BR _exit (2)
-all attached shared memory segments are detached from the process.
 .SH RETURN VALUE
-On success
+On success,
 .BR shmat ()
-returns the address of the attached shared memory segment; on error
+returns the address of the attached shared memory segment; on error,
 .I (void\ *)\ \-1
 is returned, and
 .I errno
 is set to indicate the cause of the error.
 
-On success
+On success,
 .BR shmdt ()
 returns 0; on error \-1 is returned, and
 .I errno
@@ -232,22 +229,31 @@ is not aligned on a page boundary.
 SVr4, POSIX.1-2001.
 .\" SVr4 documents an additional error condition EMFILE.
 
-In SVID 3 (or perhaps earlier)
+In SVID 3 (or perhaps earlier),
 the type of the \fIshmaddr\fP argument was changed from
-.I "char *"
+.I "char\ *"
 into
-.IR "const void *" ,
+.IR "const void\ *" ,
 and the returned type of
 .BR shmat ()
 from
-.I "char *"
+.I "char\ *"
 into
-.IR "void *" .
-(Linux libc4 and libc5 have the
-.I "char *"
-prototypes; glibc2 has
-.IR "void *" .)
+.IR "void\ *" .
 .SH NOTES
+.PP
+After a
+.BR fork (2),
+the child inherits the attached shared memory segments.
+
+After an
+.BR execve (2),
+all attached shared memory segments are detached from the process.
+
+Upon
+.BR _exit (2),
+all attached shared memory segments are detached from the process.
+
 Using
 .BR shmat ()
 with
@@ -268,20 +274,20 @@ many other implementations do not support it.
 The following system parameter affects
 .BR shmat ():
 .TP
-.\" FIXME A good explanation of the rationale for the existence
-.\" of SHMLBA would be useful here
 .B SHMLBA
 Segment low boundary address multiple.
-Must be page aligned.
-For the current implementation the
+When explicitly specifying an attach address in a call to
+.BR shmat (),
+the caller should ensure that the address is a multiple of this value.
+This is necessary on some architectures,
+in order either to ensure good CPU cache performance or to ensure that
+different attaches of the same segment have consistent views
+within the CPU cache.
 .B SHMLBA
-value is
-.BR PAGE_SIZE .
-.\" FIXME That last sentence isn't true for all Linux
-.\" architectures (i.e., SHMLBA != PAGE_SIZE for some architectures)
-.\" -- MTK, Nov 04
+is normally some multiple of the system page size
+(on many Linux architectures, it is the same as the system page size).
 .PP
-The implementation places no intrinsic limit on the per-process maximum
+The implementation places no intrinsic per-process limit on the
 number of shared memory segments
 .RB ( SHMSEG ).
 .SH SEE ALSO
@@ -292,3 +298,12 @@ number of shared memory segments
 .BR capabilities (7),
 .BR shm_overview (7),
 .BR svipc (7)
+.SH COLOPHON
+This page is part of release 3.79 of the Linux
+.I man-pages
+project.
+A description of the project,
+information about reporting bugs,
+and the latest version of this page,
+can be found at
+\%http://www.kernel.org/doc/man\-pages/.