'\" et .TH SHMAT "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual" .\" .SH PROLOG This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. .\" .SH NAME shmat \(em XSI shared memory attach operation .SH SYNOPSIS .LP .nf #include .P void *shmat(int \fIshmid\fP, const void *\fIshmaddr\fP, int \fIshmflg\fP); .fi .SH DESCRIPTION The \fIshmat\fR() function operates on XSI shared memory (see the Base Definitions volume of POSIX.1\(hy2017, .IR "Section 3.346" ", " "Shared Memory Object"). It is unspecified whether this function interoperates with the realtime interprocess communication facilities defined in .IR "Section 2.8" ", " "Realtime". .P The \fIshmat\fR() function attaches the shared memory segment associated with the shared memory identifier specified by .IR shmid to the address space of the calling process. The segment is attached at the address specified by one of the following criteria: .IP " *" 4 If .IR shmaddr is a null pointer, the segment is attached at the first available address as selected by the system. .IP " *" 4 If .IR shmaddr is not a null pointer and (\fIshmflg\fP &SHM_RND) is non-zero, the segment is attached at the address given by (\fIshmaddr\fP \-((\fIuintptr_t\fP)\fIshmaddr\fP %SHMLBA)). The character .BR '%' is the C-language remainder operator. .IP " *" 4 If .IR shmaddr is not a null pointer and (\fIshmflg\fP &SHM_RND) is 0, the segment is attached at the address given by .IR shmaddr . .IP " *" 4 The segment is attached for reading if (\fIshmflg\fP &SHM_RDONLY) is non-zero and the calling process has read permission; otherwise, if it is 0 and the calling process has read and write permission, the segment is attached for reading and writing. .SH "RETURN VALUE" Upon successful completion, \fIshmat\fR() shall increment the value of .IR shm_nattch in the data structure associated with the shared memory ID of the attached shared memory segment and return the segment's start address. Also, the .IR shm_atime timestamp shall be set to the current time, as described in .IR "Section 2.7.1" ", " "IPC General Description". .P Otherwise, the shared memory segment shall not be attached, \fIshmat\fR() shall return (\fBvoid *\fP)\-1, and .IR errno shall be set to indicate the error. .SH ERRORS The \fIshmat\fR() function shall fail if: .TP .BR EACCES Operation permission is denied to the calling process; see .IR "Section 2.7" ", " "XSI Interprocess Communication". .TP .BR EINVAL The value of .IR shmid is not a valid shared memory identifier, the .IR shmaddr is not a null pointer, and the value of (\fIshmaddr\fP \-((\fIuintptr_t\fP)\fIshmaddr\fP %SHMLBA)) is an illegal address for attaching shared memory; or the .IR shmaddr is not a null pointer, (\fIshmflg\fP &SHM_RND) is 0, and the value of .IR shmaddr is an illegal address for attaching shared memory. .TP .BR EMFILE The number of shared memory segments attached to the calling process would exceed the system-imposed limit. .TP .BR ENOMEM The available data space is not large enough to accommodate the shared memory segment. .LP .IR "The following sections are informative." .SH EXAMPLES None. .SH "APPLICATION USAGE" The POSIX Realtime Extension defines alternative interfaces for interprocess communication. Application developers who need to use IPC should design their applications so that modules using the IPC routines described in .IR "Section 2.7" ", " "XSI Interprocess Communication" can be easily modified to use the alternative interfaces. .SH RATIONALE None. .SH "FUTURE DIRECTIONS" None. .SH "SEE ALSO" .IR "Section 2.7" ", " "XSI Interprocess Communication", .IR "Section 2.8" ", " "Realtime", .IR "\fIexec\fR\^", .IR "\fIexit\fR\^(\|)", .IR "\fIfork\fR\^(\|)", .IR "\fIshmctl\fR\^(\|)", .IR "\fIshmdt\fR\^(\|)", .IR "\fIshmget\fR\^(\|)", .IR "\fIshm_open\fR\^(\|)", .IR "\fIshm_unlink\fR\^(\|)" .P The Base Definitions volume of POSIX.1\(hy2017, .IR "Section 3.346" ", " "Shared Memory Object", .IR "\fB\fP" .\" .SH COPYRIGHT Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . .PP Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .