1.\" 2.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com> 3.\" 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25.\" 26.\" $FreeBSD$ 27.\" 28.Dd August 2, 1995 29.Dt SHMAT 2 30.Os 31.Sh NAME 32.Nm shmat , 33.Nm shmdt 34.Nd attach or detach shared memory 35.Sh LIBRARY 36.Lb libc 37.Sh SYNOPSIS 38.In sys/types.h 39.In sys/ipc.h 40.In sys/shm.h 41.Ft void * 42.Fn shmat "int shmid" "const void *addr" "int flag" 43.Ft int 44.Fn shmdt "const void *addr" 45.Sh DESCRIPTION 46The 47.Fn shmat 48system call 49attaches the shared memory segment identified by 50.Fa shmid 51to the calling process's address space. 52The address where the segment 53is attached is determined as follows: 54.\" 55.\" These are cribbed almost exactly from Stevens, _Advanced Programming in 56.\" the UNIX Environment_. 57.\" 58.Bl -bullet 59.It 60If 61.Fa addr 62is 0, the segment is attached at an address selected by the 63kernel. 64.It 65If 66.Fa addr 67is nonzero and SHM_RND is not specified in 68.Fa flag , 69the segment is attached the specified address. 70.It 71If 72.Fa addr 73is specified and SHM_RND is specified, 74.Fa addr 75is rounded down to the nearest multiple of SHMLBA. 76.El 77.Pp 78The 79.Fn shmdt 80system call 81detaches the shared memory segment at the address specified by 82.Fa addr 83from the calling process's address space. 84.Sh RETURN VALUES 85Upon success, 86.Fn shmat 87returns the address where the segment is attached; otherwise, -1 88is returned and 89.Va errno 90is set to indicate the error. 91.Pp 92.Rv -std shmdt 93.Sh ERRORS 94The 95.Fn shmat 96system call 97will fail if: 98.Bl -tag -width Er 99.It Bq Er EINVAL 100No shared memory segment was found corresponding to 101.Fa shmid . 102.It Bq Er EINVAL 103The 104.Fa addr 105argument 106was not an acceptable address. 107.El 108.Pp 109The 110.Fn shmdt 111system call 112will fail if: 113.Bl -tag -width Er 114.It Bq Er EINVAL 115The 116.Fa addr 117argument 118does not point to a shared memory segment. 119.El 120.Sh "SEE ALSO" 121.Xr shmctl 2 , 122.Xr shmget 2 123