


SHMOP(2)                  SYSTEM CALLS                   SHMOP(2)



NAME
     shmop, shmat, shmdt - shared memory operations

SYNOPSIS
     #include <sys/types.h>
     #include <sys/ipc.h>
     #include <sys/shm.h>

     char *shmat(shmid, shmaddr, shmflg)
     int shmid;
     char *shmaddr;
     int shmflg;

     int shmdt(shmaddr)
     char *shmaddr;

DESCRIPTION
     shmat() maps the shared memory segment associated  with  the
     shared  memory  identifier  specified by _s_h_m_i_d into the data
     segment of the calling process.  Upon successful completion,
     the address of the mapped segment is returned.

     The shared memory segment is mapped at the address specified
     by one of the following criteria:

     o+  If _s_h_m_a_d_d_r is equal to zero, the segment is mapped at  an
        address selected by the system.  Ordinarily, applications
        should invoke shmat() with _s_h_m_a_d_d_r equal to zero so  that
        the  operating  system may make the best use of available
        resources.

     o+  If _s_h_m_a_d_d_r is not equal to zero and (_s_h_m_f_l_g & SHM_RND) is
        ``true'',  the  segment is mapped at the address given by
        (_s_h_m_a_d_d_r - (_s_h_m_a_d_d_r modulus SHMLBA)).

     o+  If _s_h_m_a_d_d_r is not equal to zero and (_s_h_m_f_l_g & SHM_RND) is
        ``false'',  the segment is mapped at the address given by
        _s_h_m_a_d_d_r.

     The segment is mapped for reading if (_s_h_m_f_l_g  &  SHM_RDONLY)
     is  ``true''  [READ], otherwise it is mapped for reading and
     writing [READ/WRITE] (see shmctl(2)).

     shmdt() unmaps from the calling process's address space  the
     shared  memory  segment that is mapped at the address speci-
     fied by _s_h_m_a_d_d_r.  The shared memory segment must  have  been
     mapped  with a prior shmat() function call.  The segment and
     contents are retained until explicitly removed by  means  of
     the IPC_RMID function (see shmctl(2)).

RETURN VALUES
     shmat() returns the data segment start address of the mapped



Sun Release 4.1   Last change: 21 January 1990                  1






SHMOP(2)                  SYSTEM CALLS                   SHMOP(2)



     shared  memory  segment.  On failure, it returns -1 and sets
     errno to indicate the error.

     shmdt() returns:

     0    on success.

     -1   on failure and sets errno to indicate the error.

ERRORS
     shmat() will fail and not map the shared memory  segment  if
     one or more of the following are true:

     EACCES         Operation permission is denied to the calling
                    process (see intro(2)).

     EINVAL         _s_h_m_i_d is not a valid shared  memory  identif-
                    ier.

                    _s_h_m_a_d_d_r is not equal to zero, and  the  value
                    of (_s_h_m_a_d_d_r - (_s_h_m_a_d_d_r modulus SHMLBA)) is an
                    illegal address.

                    _s_h_m_a_d_d_r is  not  equal  to  zero,  (_s_h_m_f_l_g  &
                    SHM_RND)  is  ``false'',  and  the  value  of
                    _s_h_m_a_d_d_r is an illegal address.

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

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

     shmdt() will fail and not unmap the  shared  memory  segment
     if:

     EINVAL         _s_h_m_a_d_d_r is not the data segment start address
                    of a shared memory segment.

SEE ALSO
     ipcrm(1), ipcs(1), intro(2), execve(2V), exit(2V), fork(2V),
     shmctl(2), shmget(2)












Sun Release 4.1   Last change: 21 January 1990                  2



