SHMAT(3)                   POSIX Programmer's Manual                  SHMAT(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       shmat -- XSI shared memory attach operation

SSYYNNOOPPSSIISS
       #include <sys/shm.h>

       void *shmat(int _s_h_m_i_d, const void *_s_h_m_a_d_d_r, int _s_h_m_f_l_g);

DDEESSCCRRIIPPTTIIOONN
       The _s_h_m_a_t() function operates on XSI shared memory (see the Base
       Definitions volume of POSIX.1-2017, _S_e_c_t_i_o_n _3_._3_4_6, _S_h_a_r_e_d _M_e_m_o_r_y
       _O_b_j_e_c_t).  It is unspecified whether this function interoperates with
       the realtime interprocess communication facilities defined in _S_e_c_t_i_o_n
       _2_._8, _R_e_a_l_t_i_m_e.

       The _s_h_m_a_t() function attaches the shared memory segment associated with
       the shared memory identifier specified by _s_h_m_i_d to the address space of
       the calling process. The segment is attached at the address specified
       by one of the following criteria:

        *  If _s_h_m_a_d_d_r is a null pointer, the segment is attached at the first
           available address as selected by the system.

        *  If _s_h_m_a_d_d_r is not a null pointer and (_s_h_m_f_l_g &SHM_RND) is non-zero,
           the segment is attached at the address given by (_s_h_m_a_d_d_r
           -((_u_i_n_t_p_t_r___t)_s_h_m_a_d_d_r %SHMLBA)). The character ''%%'' is the C-language
           remainder operator.

        *  If _s_h_m_a_d_d_r is not a null pointer and (_s_h_m_f_l_g &SHM_RND) is 0, the
           segment is attached at the address given by _s_h_m_a_d_d_r.

        *  The segment is attached for reading if (_s_h_m_f_l_g &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.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _s_h_m_a_t() shall increment the value of
       _s_h_m___n_a_t_t_c_h 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 _s_h_m___a_t_i_m_e timestamp shall be set to the current
       time, as described in _S_e_c_t_i_o_n _2_._7_._1, _I_P_C _G_e_n_e_r_a_l _D_e_s_c_r_i_p_t_i_o_n.

       Otherwise, the shared memory segment shall not be attached, _s_h_m_a_t()
       shall return (vvooiidd **)-1, and _e_r_r_n_o shall be set to indicate the error.

EERRRROORRSS
       The _s_h_m_a_t() function shall fail if:

       EEAACCCCEESS Operation permission is denied to the calling process; see
              _S_e_c_t_i_o_n _2_._7, _X_S_I _I_n_t_e_r_p_r_o_c_e_s_s _C_o_m_m_u_n_i_c_a_t_i_o_n.

       EEIINNVVAALL The value of _s_h_m_i_d is not a valid shared memory identifier, the
              _s_h_m_a_d_d_r is not a null pointer, and the value of (_s_h_m_a_d_d_r
              -((_u_i_n_t_p_t_r___t)_s_h_m_a_d_d_r %SHMLBA)) is an illegal address for
              attaching shared memory; or the _s_h_m_a_d_d_r is not a null pointer,
              (_s_h_m_f_l_g &SHM_RND) is 0, and the value of _s_h_m_a_d_d_r is an illegal
              address for attaching shared memory.

       EEMMFFIILLEE The number of shared memory segments attached to the calling
              process would exceed the system-imposed limit.

       EENNOOMMEEMM The available data space is not large enough to accommodate the
              shared memory segment.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
       None.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       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 _S_e_c_t_i_o_n _2_._7, _X_S_I _I_n_t_e_r_p_r_o_c_e_s_s _C_o_m_m_u_n_i_c_a_t_i_o_n can be easily
       modified to use the alternative interfaces.

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _S_e_c_t_i_o_n _2_._7, _X_S_I _I_n_t_e_r_p_r_o_c_e_s_s _C_o_m_m_u_n_i_c_a_t_i_o_n, _S_e_c_t_i_o_n _2_._8, _R_e_a_l_t_i_m_e,
       _e_x_e_c, _e_x_i_t(), _f_o_r_k(), _s_h_m_c_t_l(), _s_h_m_d_t(), _s_h_m_g_e_t(), _s_h_m___o_p_e_n(),
       _s_h_m___u_n_l_i_n_k()

       The Base Definitions volume of POSIX.1-2017, _S_e_c_t_i_o_n _3_._3_4_6, _S_h_a_r_e_d
       _M_e_m_o_r_y _O_b_j_e_c_t, <<ssyyss__sshhmm..hh>>

CCOOPPYYRRIIGGHHTT
       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 .

       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 .



IEEE/The Open Group                  2017                             SHMAT(3)
