SHMGET(3)                  POSIX Programmer's Manual                 SHMGET(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
       shmget -- get an XSI shared memory segment

SSYYNNOOPPSSIISS
       #include <sys/shm.h>

       int shmget(key_t _k_e_y, size_t _s_i_z_e, int _s_h_m_f_l_g);

DDEESSCCRRIIPPTTIIOONN
       The _s_h_m_g_e_t() function operates on XSI shared memory (see the Base
       Definitions volume of POSIX.1-2008, _S_e_c_t_i_o_n _3_._3_4_2, _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_g_e_t() function shall return the shared memory identifier
       associated with _k_e_y.

       A shared memory identifier, associated data structure, and shared
       memory segment of at least _s_i_z_e bytes (see _<_s_y_s_/_s_h_m_._h_>) are created for
       _k_e_y if one of the following is true:

        *  The argument _k_e_y is equal to IPC_PRIVATE.

        *  The argument _k_e_y does not already have a shared memory identifier
           associated with it and (_s_h_m_f_l_g &IPC_CREAT) is non-zero.

       Upon creation, the data structure associated with the new shared memory
       identifier shall be initialized as follows:

        *  The values of _s_h_m___p_e_r_m_._c_u_i_d, _s_h_m___p_e_r_m_._u_i_d, _s_h_m___p_e_r_m_._c_g_i_d, and
           _s_h_m___p_e_r_m_._g_i_d are set to the effective user ID and effective group
           ID, respectively, of the calling process.

        *  The low-order nine bits of _s_h_m___p_e_r_m_._m_o_d_e are set to the low-order
           nine bits of _s_h_m_f_l_g.

        *  The value of _s_h_m___s_e_g_s_z is set to the value of _s_i_z_e.

        *  The values of _s_h_m___l_p_i_d, _s_h_m___n_a_t_t_c_h, _s_h_m___a_t_i_m_e, and _s_h_m___d_t_i_m_e are
           set to 0.

        *  The value of _s_h_m___c_t_i_m_e is 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.

       When the shared memory segment is created, it shall be initialized with
       all zero values.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _s_h_m_g_e_t() shall return a non-negative
       integer, namely a shared memory identifier; otherwise, it shall return
       -1 and set _e_r_r_n_o to indicate the error.

EERRRROORRSS
       The _s_h_m_g_e_t() function shall fail if:

       EEAACCCCEESS A shared memory identifier exists for _k_e_y but operation
              permission as specified by the low-order nine bits of _s_h_m_f_l_g
              would not be granted; 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.

       EEEEXXIISSTT A shared memory identifier exists for the argument _k_e_y but
              (_s_h_m_f_l_g &IPC_CREAT) &&(_s_h_m_f_l_g &IPC_EXCL) is non-zero.

       EEIINNVVAALL A shared memory segment is to be created and the value of size
              is less than the system-imposed minimum or greater than the
              system-imposed maximum.

       EEIINNVVAALL No shared memory segment is to be created and a shared memory
              segment exists for _k_e_y but the size of the segment associated
              with it is less than _s_i_z_e.

       EENNOOEENNTT A shared memory identifier does not exist for the argument _k_e_y
              and (_s_h_m_f_l_g &IPC_CREAT) is 0.

       EENNOOMMEEMM A shared memory identifier and associated shared memory segment
              shall be created, but the amount of available physical memory is
              not sufficient to fill the request.

       EENNOOSSPPCC A shared memory identifier is to be created, but the system-
              imposed limit on the maximum number of allowed shared memory
              identifiers system-wide would be exceeded.

       _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,
       _f_t_o_k(), _s_h_m_a_t(), _s_h_m_c_t_l(), _s_h_m_d_t(), _s_h_m___o_p_e_n(), _s_h_m___u_n_l_i_n_k()

       The Base Definitions volume of POSIX.1-2008, _S_e_c_t_i_o_n _3_._3_4_2, _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, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) 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.unix.org/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                  2013                            SHMGET(3)
