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.Dd October 10, 2015 27.Dt SHMCTL 2 28.Os 29.Sh NAME 30.Nm shmctl 31.Nd shared memory control 32.Sh LIBRARY 33.Lb libc 34.Sh SYNOPSIS 35.In sys/types.h 36.In sys/ipc.h 37.In sys/shm.h 38.Ft int 39.Fn shmctl "int shmid" "int cmd" "struct shmid_ds *buf" 40.Sh DESCRIPTION 41Performs the action specified by 42.Fa cmd 43on the shared memory segment identified by 44.Fa shmid : 45.Bl -tag -width SHM_UNLOCKX 46.It Dv IPC_STAT 47Fetch the segment's 48.Fa "struct shmid_ds" , 49storing it in the memory pointed to by 50.Fa buf . 51.\" 52.\" XXX need to make sure that this is correct for FreeBSD 53.\" 54.It Dv IPC_SET 55Changes the 56.Fa shm_perm.uid , 57.Fa shm_perm.gid , 58and 59.Fa shm_perm.mode 60members of the segment's 61.Fa "struct shmid_ds" 62to match those of the struct pointed to by 63.Fa buf . 64The calling process's effective uid must 65match either 66.Fa shm_perm.uid 67or 68.Fa shm_perm.cuid , 69or it must have superuser privileges. 70.It Dv IPC_RMID 71Removes the segment from the system. 72The removal will not take 73effect until all processes having attached the segment have exited. 74For the operation 75to succeed, the calling process's effective uid must match 76.Fa shm_perm.uid 77or 78.Fa shm_perm.cuid , 79or the process must have superuser privileges. 80If the 81.Va kern.ipc.shm_allow_removed 82.Xr sysctl 3 83variable is set to 0, once the IPC_RMID operation has taken place, 84no further processes will be allowed to attach the segment. 85.\" .It Dv SHM_LOCK 86.\" Locks the segment in memory. The calling process must have 87.\" superuser privileges. Not implemented in FreeBSD. 88.\" .It Dv SHM_UNLOCK 89.\" Unlocks the segment from memory. The calling process must 90.\" have superuser privileges. Not implemented in FreeBSD. 91.El 92.Pp 93The 94.Vt shmid_ds 95structure is defined as follows: 96.\" 97.\" I fiddled with the spaces a bit to make it fit well when viewed 98.\" with nroff, but otherwise it is straight from sys/shm.h 99.\" 100.Bd -literal 101struct shmid_ds { 102 struct ipc_perm shm_perm; /* operation permission structure */ 103 size_t shm_segsz; /* size of segment in bytes */ 104 pid_t shm_lpid; /* process ID of last shared memory op */ 105 pid_t shm_cpid; /* process ID of creator */ 106 int shm_nattch; /* number of current attaches */ 107 time_t shm_atime; /* time of last shmat() */ 108 time_t shm_dtime; /* time of last shmdt() */ 109 time_t shm_ctime; /* time of last change by shmctl() */ 110}; 111.Ed 112.Sh RETURN VALUES 113.Rv -std shmctl 114.Sh ERRORS 115The 116.Fn shmctl 117system call 118will fail if: 119.Bl -tag -width Er 120.It Bq Er EINVAL 121Invalid operation, or 122no shared memory segment was found corresponding to 123.Fa shmid . 124.\" 125.\" XXX I think the following is right: ipcperm() only returns EPERM 126.\" when an attempt is made to modify (IPC_M) by a non-creator 127.\" non-owner 128.It Bq Er EPERM 129The calling process's effective uid does not match the uid of 130the shared memory segment's owner or creator. 131.It Bq Er EACCES 132Permission denied due to mismatch between operation and mode of 133shared memory segment. 134.El 135.Sh "SEE ALSO" 136.Xr shmat 2 , 137.Xr shmdt 2 , 138.Xr shmget 2 , 139.Xr ftok 3 140