unixdev.net


Switch to SpeakEasy.net DSL

The Modular Manual Browser

Home Page
Manual: (OSF1-V5.1-alpha)
Page:
Section:
Apropos / Subsearch:
optional field



shmget(2)							    shmget(2)



NAME
  shmget - Returns (and	possibly creates) the ID for a shared memory region

SYNOPSIS

  #include <&lt;sys/shm.h>&gt;

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

  If programs are being	developed for multiple platforms, application
  developers may want to specify #include statements for <&lt;sys/types.h>&gt; and
  <&lt;sys/ipc.h>&gt; before the one for <&lt;sys/shm.h>&gt;.  The additional #include state-
  ments	are not	required on Tru64 UNIX systems or by ISO or X/Open standards,
  but may be required on other vendors'	systems	that conform to	these stan-
  dards.

STANDARDS

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

  shmget():  XSH4.2

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

PARAMETERS

  key	    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 a new, unused shared memory
	    region.

  size	    Specifies the minimum number of bytes to allocate for the region.

  flags	    Specifies the creation flags.  Possible values are:

	    IPC_CREAT If the key specified does	not exist, the shmget()	func-
		      tion creates an ID using the specified key.

		      If the specified key does	exist, and IPC_EXCL is not
		      set, the ID 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.

	    IPC_EXCL  If the key already exists, the shmget() function fails
		      and returns an error notification.

DESCRIPTION

  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	kernel-assigned	ID
  for the region.

  After	creating a new shared memory region ID,	the shmget() function ini-
  tializes the shmid_ds	structure associated with the ID as follows:

    +  The shm_perm.cuid and shm_perm.uid fields are set equal to the effec-
       tive user ID of the calling process.

    +  The shm_perm.cgid and shm_perm.gid fields are set equal to the effec-
       tive 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	cal-
       ling 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 ssm-threshold (an attribute in /etc/sysconfigtab), the memory
  region is managed using shared page tables.  When attaching to such a	seg-
  ment,	the segment must always	be aligned and sized correctly.	 The align-
  ment 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.)

RETURN VALUES

  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

  The shmget() function	sets errno to the specified values for the following
  conditions:

  [EACCES]  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.

  [EEXIST]  A shared memory region ID already exists for the key parameter,
	    but	IPC_CREAT and IPC_EXCL were used for the flags parameter.

  [EINVAL]  The	value of the size parameter is less than the system-defined
	    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).

  [ENOENT]  A shared memory region ID does not exist for the key parameter,
	    and	IPC_CREAT was not used for the flags parameter.

  [ENOMEM]  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.

  [ENOSPC]  An attempt to create a new shared memory region ID exceeded	the
	    system-wide	limit on the maximum number of IDs allowed.

RELATED	INFORMATION

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

  Files: shmid_ds(4)

  Standards: standards(5)