*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->Tru64 Unix man pages -> shmget (2)              
Title
Content
Arch
Section
 

shmget(2)

Contents


NAME    [Toc]    [Back]

       shmget  - Return (and possibly create) the ID for a shared
       memory region

SYNOPSIS    [Toc]    [Back]

       #include <sys/shm.h>

       int shmget(
               key_t key,
               size_t size,
               int flags );

       Application developers  might  want  to  specify  #include
       statements  for  <sys/types.h>  and <sys/ipc.h> before the
       one for <sys/shm.h> if programs are  being  developed  for
       multiple  platforms.   The  additional #include statements
       are not required on Tru64 UNIX systems or by  ISO  or  XSH
       specifications,  but  might  be required on other vendors'
       systems that conform to these standards.

STANDARDS    [Toc]    [Back]

       Interfaces documented on this reference  page  conform  to
       industry standards as follows:

       shmget(): XSH4.0, XSH4.2, XSH5.0

       Refer to the standards(5) reference page for more information
 about industry standards and associated tags.

PARAMETERS    [Toc]    [Back]

       Specifies  the  key  that  identifies  the  shared  memory
       region. The value for the key parameter can be IPC_PRIVATE
       or a random number other than zero (0). If  the  value  of
       key is IPC_PRIVATE, it can be used to assure the return of
       the identifier of a  new,  unused  shared  memory  region.
       Specifies  the minimum number of bytes to allocate for the
       region.  Specifies the creation options.  Possible  values
       are:  If  the  specified  key does not exist, the shmget()
       function creates a shared memory identifier for the specified
 key.

              If  the  specified  key does exist, and IPC_EXCL is
              not set, the shared memory identifier for the specified
 key is returned.

              If  the  specified  key  does exist and IPC_EXCL is
              set, the shmget() function  fails  and  returns  an
              error.   If  the  key  already exists, the shmget()
              function fails and returns an error notification.

DESCRIPTION    [Toc]    [Back]

       The shmget() function returns (and possibly  creates)  the
       ID  for  the  shared  memory  region identified by the key
       parameter. If IPC_PRIVATE is used for the  key  parameter,
       the  shmget()  function returns the ID for a private (that
       is, newly created) shared memory region. The flags parameter
  supplies  creation options for the shmget() function.
       If the key parameter does not already exist, the IPC_CREAT
       flag  instructs  the  shmget()  function  to  create a new
       shared memory region for the key and  return  the  kernelassigned
 ID for the region.

       After creating a new shared memory region ID, the shmget()
       function initializes  the  shmid_ds  structure  associated
       with the ID as follows: The shm_perm.cuid and shm_perm.uid
       fields are set equal to the effective user ID of the calling
  process.   The  shm_perm.cgid and shm_perm.gid fields
       are set equal to the effective group  ID  of  the  calling
       process.   The  low-order  nine  bits of the shm_perm.mode
       field are set equal to the low-order nine bits  of  flags.
       The  shm_segsz  field is set equal to size.  The shm_lpid,
       shm_nattch, shm_atime, and shm_dtime fields  are  all  set
       equal  to  0  (zero).  The shm_ctime field is set equal to
       the current time.  [Tru64 UNIX]  The shm_cpid field is set
       to the process ID of the calling process.

       [Tru64  UNIX]  To reduce the overhead associated with managing
 large shared memory regions  among  many  processes,
       the  Tru64  UNIX  kernel  makes use of shared page tables,
       also referred to as segmented shared  memory  (SSM).  When
       the  segment size requested by shmget() is greater than or
       equal to the value of the ssm_threshold system  attribute,
       the  memory  region  is  managed using shared page tables.
       When attaching to such a segment, the segment must  always
       be  aligned  and  sized  correctly. The alignment and size
       factor is given by the system-defined SSM_SIZE value  (see
       <machine/pmap.h>).  When  the  attachment occurs, the segment's
 memory region is aligned on  an  SSM_SIZE  boundary
       and  its  size  is  rounded up to the next SSM_SIZE boundary--thus,
 the segment size specified by shmget() does not
       need  to  be  a  multiple  of  SSM_SIZE.  Use of segmented
       shared memory can be disabled by setting the ssm_threshold
       attribute to zero.

       For more information on segmented shared memory and interprocess
 communication, see the system  attribute  descriptions
  in  sys_attrs_ipc(5)  and  the discussion of tuning
       interprocess communication limits in the System Configuration
 and Tuning guide.

NOTES    [Toc]    [Back]

       The  librt  library  contains  alternative  interfaces for
       interprocess communication. The names  of  these  routines
       adhere  to  the format shm_* and their reference pages are
       listed in SEE ALSO.

RETURN VALUES    [Toc]    [Back]

       Upon successful completion, a shared memory identifier  is
       returned.   If  the shmget() function fails, a value of -1
       is returned and errno is set to indicate the error.

ERRORS    [Toc]    [Back]

       The shmget() function sets errno to the  specified  values
       for  the  following  conditions: A shared memory region ID
       already exists for the key parameter, but  operation  permission
  as  specified  by  the low-order nine bits of the
       flags parameter was not granted.  A shared  memory  region
       ID already exists for the key parameter, but IPC_CREAT and
       IPC_EXCL were specified  for  the  flags  parameter.   The
       value  of  the  size  parameter  is  less than the systemdefined
 minimum or greater than the  system-defined  maximum.
  Or, a shared memory region ID already exists for the
       key parameter, but the number of bytes allocated  for  the
       region  is  less  than  size  and  size  is not equal to 0
       (zero).  A shared memory region ID does not exist for  the
       key  parameter,  and  IPC_CREAT was not used for the flags
       parameter.  An attempt was made to create a shared  memory
       region ID and its associated shmid_ds structure, but there
       was not enough physical memory available.  An  attempt  to
       create  a new shared memory region ID exceeded the systemwide
 limit on the maximum number of IDs allowed.

SEE ALSO    [Toc]    [Back]

      
      
       Functions: shmat(2),  shmctl(2),  shmdt(2),  sysconfig(8),
       table(2), ftok(3), shm_open(3), shm_unlink(3)

       Files: shmid_ds(4)

       Standards: standards(5)



                                                        shmget(2)
[ Back ]
 Similar pages
Name OS Title
semget Tru64 Return (and possibly create) a semaphore ID
msgget Tru64 Return (and possibly create) the ID for a message queue
shmid_ds Tru64 Defines a shared memory region
shmdt Tru64 Detach a shared memory region
shmat Tru64 Attach a shared memory region
nshmget Tru64 Returns (or creates) the ID for a shared memory region (libnuma library)
msem_init Tru64 Initialize a semaphore in a mapped file or shared memory region
shm_open FreeBSD open or create a shared memory object shm_unlink -- remove a shared memory object
shm_open HP-UX create/open a shared memory object
open Linux open and possibly create a file or device
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service