NAME
	  shmat	-  Attaches a shared memory region

     SYNOPSIS
	  #include <sys/types.h>
	  #include <sys/ipc.h>
	  #include <sys/shm.h>
	  void *shmat(
	       int shmid,
	       void *shmaddr,
	       int shmflg);


     PARAMETERS
	  shmid	    Specifies the ID for the shared memory region.
		    The	ID is typically	returned by a previous
		    shmget() function.

	  addr	    Specifies the virtual address at which the process
		    wants to attach the	shared memory region.  The
		    process can	also specify 0 (zero) to have the ker-
		    nel	select an appropriate address.

	  flags	    Specifies the attach flags.	 Possible values are:


		    SHM_RND   If the addr parameter is not 0 (zero),
			      the kernel rounds	off the	address, if
			      necessary.

		    SHM_RDONLY
			      If the calling process has read permis-
			      sion, the	kernel attaches	the region for
			      reading only.


     DESCRIPTION
	  The shmat() function attaches	the shared memory region iden-
	  tified by the	shmid parameter	to the virtual address space
	  of the calling process.  For the addr	parameter, the process
	  can specify either an	explicit address or 0 (zero), to have
	  the kernel select the	address.  If an	explicit address is
	  used,	the process can	set the	SHM_RND	flag to	have the ker-
	  nel round off	the address, if	necessary.

	  Access to the	shared memory region is	determined by the
	  operation permissions	in the shm_perm.mode member in the
	  region's shmid_ds structure.	The low-order bits in
	  shm_perm.mode	are interpreted	as follows:

	  00400	    Read by user

	  00200	    Write by user

	  00040	    Read by group

	  00020	    Write by group

	  00004	    Read by others

	  00002	    Write by others


	  The calling process is granted read and write	permissions on
	  the attached region if at least one of the following is
	  true:


	    o  The effective user ID of	the process is superuser.

	    o  The effective user ID of	the process is equal to
	       shm_perm.cuid or	shm_perm.uid and bit 0600  in
	       shm_perm.mode is	set.

	    o  The effective group ID of the process is	equal to
	       shm_perm.cgid or	shm_perm.gid and bit 0060  in
	       shm_perm.mode is	set.

	    o  Bit 0006	 in shm_perm.mode is set.


	  If the process has read permission, it can attach the	region
	  as read only by setting the SHM_RDONLY flag.

     RETURN VALUES
	  Upon successful completion, the starting address for the
	  attached region is returned. If the shmat() function fails,
	  a value of -1	is returned and	errno is set to	indicate the
	  error.

     ERRORS
	  If the shmat() function fails, the shared memory region is
	  not attached and errno may be	set to one of the following
	  values:


	  [EACCES]  The	calling	process	does not have the appropriate
		    privilege.

	  [ENOMEM]  There was not enough data space available to
		    attach the shared memory region.

	  [EINVAL]  The	shmid parameter	does not specify a valid
		    shared memory region ID; the addr parameter	is not
		    0 (zero) and not a valid address; or the addr
		    parameter is not 0 (zero) and not a	valid address,
		    and	SHM_RND	is not set.

	  [EMFILE]  An attempt to attach a shared memory region
		    exceeded the maximum number	of attached regions
		    allowed for	any one	process.


	  [ENOSYS]  The	requested operation is not supported by	this
		    implementation.


     RELATED INFORMATION
	  Functions: exec(2), exit(2), fork(2),	shmctl(2), shmdt(2),
	  shmget(2)

	  Data structures: shmid_ds(4)


































Acknowledgement and Disclaimer