# shmctl

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


## NAME



           shmctl — XSI shared memory control operations
    


## SYNOPSIS



           #include <sys/shm.h>
    
           int shmctl(int _shmid_ , int _cmd_ , struct shmid_ds *_buf_);
    


## DESCRIPTION



           The _shmctl_() function operates on XSI shared memory (see the Base
           Definitions volume of POSIX.1‐2017, _Section 3.346_ , _Shared Memory_
           _Object_).  It is unspecified whether this function interoperates
           with the realtime interprocess communication facilities defined in
           _Section 2.8_ , _Realtime_.
    
           The _shmctl_() function provides a variety of shared memory control
           operations as specified by _cmd_.  The following values for _cmd_ are
           available:
    
           IPC_STAT    Place the current value of each member of the **shmid_ds**
                       data structure associated with _shmid_ into the
                       structure pointed to by _buf_.  The contents of the
                       structure are defined in _< sys/shm.h>_.
    
           IPC_SET     Set the value of the following members of the **shmid_ds**
                       data structure associated with _shmid_ to the
                       corresponding value found in the structure pointed to
                       by _buf_ :
    
                           shm_perm.uid
                           shm_perm.gid
                           shm_perm.mode    Low-order nine bits.
    
                       Also, the _shm_ctime_ timestamp shall be set to the
                       current time, as described in _Section 2.7.1_ , _IPC_
                       _General Description_.
    
                       IPC_SET can only be executed by a process that has an
                       effective user ID equal to either that of a process
                       with appropriate privileges or to the value of
                       _shm_perm.cuid_ or _shm_perm.uid_ in the **shmid_ds** data
                       structure associated with _shmid_.
    
           IPC_RMID    Remove the shared memory identifier specified by _shmid_
                       from the system and destroy the shared memory segment
                       and **shmid_ds** data structure associated with it.
                       IPC_RMID can only be executed by a process that has an
                       effective user ID equal to either that of a process
                       with appropriate privileges or to the value of
                       _shm_perm.cuid_ or _shm_perm.uid_ in the **shmid_ds** data
                       structure associated with _shmid_.
    


## RETURN VALUE



           Upon successful completion, _shmctl_() shall return 0; otherwise, it
           shall return -1 and set _errno_ to indicate the error.
    


## ERRORS



           The _shmctl_() function shall fail if:
    
           **EACCES** The argument _cmd_ is equal to IPC_STAT and the calling
                  process does not have read permission; see _Section 2.7_ , _XSI_
                  _Interprocess Communication_.
    
           **EINVAL** The value of _shmid_ is not a valid shared memory identifier,
                  or the value of _cmd_ is not a valid command.
    
           **EPERM** The argument _cmd_ is equal to IPC_RMID or IPC_SET and the
                  effective user ID of the calling process is not equal to
                  that of a process with appropriate privileges and it is not
                  equal to the value of _shm_perm.cuid_ or _shm_perm.uid_ in the
                  data structure associated with _shmid_.
    
           The _shmctl_() function may fail if:
    
           **EOVERFLOW**
                  The _cmd_ argument is IPC_STAT and the _gid_ or _uid_ value is
                  too large to be stored in the structure pointed to by the
                  _buf_ argument.
    
           _The following sections are informative._
    


## EXAMPLES



           None.
    


## 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 _Section 2.7_ , _XSI Interprocess Communication_
           can be easily modified to use the alternative interfaces.
    


## RATIONALE



           None.
    


## FUTURE DIRECTIONS



           None.
    


* * *