1.\" Copyright (c) 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. Neither the name of the University nor the names of its contributors 13.\" may be used to endorse or promote products derived from this software 14.\" without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.\" From: @(#)sysctl.8 8.1 (Berkeley) 6/6/93 29.\" 30.Dd December 24, 2022 31.Dt SYSCTL 8 32.Os 33.Sh NAME 34.Nm sysctl 35.Nd get or set kernel state 36.Sh SYNOPSIS 37.Nm 38.Op Fl bdeFhilNnoTtqWx 39.Op Fl B Ar bufsize 40.Op Fl f Ar filename 41.Ar name Ns Op = Ns Ar value Ns Op , Ns Ar value 42.Ar ... 43.Nm 44.Op Fl bdeFhlNnoTtqWx 45.Op Fl B Ar bufsize 46.Fl a 47.Sh DESCRIPTION 48The 49.Nm 50utility retrieves kernel state and allows processes with appropriate 51privilege to set kernel state. 52The state to be retrieved or set is described using a 53.Dq Management Information Base 54.Pq Dq MIB 55style name, described as a dotted set of 56components. 57.Pp 58The following options are available: 59.Bl -tag -width indent 60.It Fl A 61Equivalent to 62.Fl o a 63(for compatibility). 64.It Fl a 65List all the currently available values except for those which are 66opaque or excluded from listing via the 67.Dv CTLFLAG_SKIP 68flag. 69This option is ignored if one or more variable names are specified on 70the command line. 71.It Fl b 72Force the value of the variable(s) to be output in raw, binary format. 73No names are printed and no terminating newlines are output. 74This is mostly useful with a single variable. 75.It Fl B Ar bufsize 76Set the buffer size to read from the 77.Nm 78to 79.Ar bufsize . 80This is necessary for a 81.Nm 82that has variable length, and the probe value of 0 is a valid length, such as 83.Va kern.arandom . 84.It Fl d 85Print the description of the variable instead of its value. 86.It Fl e 87Separate the name and the value of the variable(s) with 88.Ql = . 89This is useful for producing output which can be fed back to the 90.Nm 91utility. 92This option is ignored if either 93.Fl N 94or 95.Fl n 96is specified, or a variable is being set. 97.It Fl f Ar filename 98Specify a file which contains a pair of name and value in each line. 99.Nm 100reads and processes the specified file first and then processes the name 101and value pairs in the command line argument. 102.It Fl F 103Print the format of the variable. 104This is additional information to describe the type of the variable and 105most useful with struct types such as clockinfo, timeval, and loadavg. 106.It Fl h 107Format output for human, rather than machine, readability. 108.It Fl i 109Ignore unknown OIDs. 110The purpose is to make use of 111.Nm 112for collecting data from a variety of machines (not all of which 113are necessarily running exactly the same software) easier. 114.It Fl l 115Show the length of variables along with their values. 116This option cannot be combined with the 117.Fl N 118option. 119.It Fl N 120Show only variable names, not their values. 121This is particularly useful with shells that offer programmable 122completion. 123To enable completion of variable names in 124.Xr zsh 1 Pq Pa ports/shells/zsh , 125use the following code: 126.Bd -literal -offset indent 127listsysctls () { set -A reply $(sysctl -AN ${1%.*}) } 128compctl -K listsysctls sysctl 129.Ed 130.Pp 131To enable completion of variable names in 132.Xr tcsh 1 , 133use: 134.Pp 135.Dl "complete sysctl 'n/*/`sysctl -Na`/'" 136.It Fl n 137Do not show variable names. 138This option is useful for setting shell variables. 139For instance, to save the pagesize in variable 140.Va psize , 141use: 142.Pp 143.Dl "set psize=`sysctl -n hw.pagesize`" 144.It Fl o 145Show opaque variables (which are normally suppressed). 146The format and length are printed, as well as a hex dump of the first 147sixteen bytes of the value. 148.It Fl q 149Suppress some warnings generated by 150.Nm 151to standard error. 152.It Fl T 153Display only variables that are settable via loader (CTLFLAG_TUN). 154.It Fl t 155Print the type of the variable. 156.It Fl W 157Display only writable variables that are not statistical. 158Useful for determining the set of runtime tunable sysctls. 159.It Fl X 160Equivalent to 161.Fl x a 162(for compatibility). 163.It Fl x 164As 165.Fl o , 166but prints a hex dump of the entire value instead of just the first 167few bytes. 168.El 169.Pp 170The information available from 171.Nm 172consists of integers, strings, and opaque types. 173The 174.Nm 175utility 176only knows about a couple of opaque types, and will resort to hexdumps 177for the rest. 178The opaque information is much more useful if retrieved by special 179purpose programs such as 180.Xr ps 1 , 181.Xr systat 1 , 182and 183.Xr netstat 1 . 184.Pp 185Some of the variables which cannot be modified during normal system 186operation can be initialized via 187.Xr loader 8 188tunables. 189This can for example be done by setting them in 190.Xr loader.conf 5 . 191Please refer to 192.Xr loader.conf 5 193for more information on which tunables are available and how to set them. 194.Pp 195The string and integer information is summarized below. 196For a detailed description of these variables see 197.Xr sysctl 3 . 198.Pp 199The changeable column indicates whether a process with appropriate 200privilege can change the value. 201String and integer values can be set using 202.Nm . 203.Bl -column security.bsd.unprivileged_read_msgbuf integerxxx 204.It Sy "Name Type Changeable" 205.It "kern.ostype string no" 206.It "kern.osrelease string no" 207.It "kern.osrevision integer no" 208.It "kern.version string no" 209.It "kern.maxvnodes integer yes" 210.It "kern.maxproc integer no" 211.It "kern.maxprocperuid integer yes" 212.It "kern.maxfiles integer yes" 213.It "kern.maxfilesperproc integer yes" 214.It "kern.argmax integer no" 215.It "kern.securelevel integer raise only" 216.It "kern.hostname string yes" 217.It "kern.hostid integer yes" 218.It "kern.clockrate struct no" 219.It "kern.posix1version integer no" 220.It "kern.ngroups integer no" 221.It "kern.job_control integer no" 222.It "kern.saved_ids integer no" 223.It "kern.boottime struct no" 224.It "kern.domainname string yes" 225.It "kern.filedelay integer yes" 226.It "kern.dirdelay integer yes" 227.It "kern.metadelay integer yes" 228.It "kern.osreldate integer no" 229.It "kern.bootfile string yes" 230.It "kern.corefile string yes" 231.It "kern.logsigexit integer yes" 232.It "security.bsd.suser_enabled integer yes" 233.It "security.bsd.see_other_uids integer yes" 234.It "security.bsd.unprivileged_proc_debug integer yes" 235.It "security.bsd.unprivileged_read_msgbuf integer yes" 236.It "vm.loadavg struct no" 237.It "hw.machine string no" 238.It "hw.model string no" 239.It "hw.ncpu integer no" 240.It "hw.byteorder integer no" 241.It "hw.physmem integer no" 242.It "hw.usermem integer no" 243.It "hw.pagesize integer no" 244.It "hw.floatingpoint integer no" 245.It "hw.machine_arch string no" 246.It "hw.realmem integer no" 247.It "machdep.adjkerntz integer yes" 248.It "machdep.disable_rtc_set integer yes" 249.It "machdep.guessed_bootdev string no" 250.It "user.cs_path string no" 251.It "user.bc_base_max integer no" 252.It "user.bc_dim_max integer no" 253.It "user.bc_scale_max integer no" 254.It "user.bc_string_max integer no" 255.It "user.coll_weights_max integer no" 256.It "user.expr_nest_max integer no" 257.It "user.line_max integer no" 258.It "user.re_dup_max integer no" 259.It "user.posix2_version integer no" 260.It "user.posix2_c_bind integer no" 261.It "user.posix2_c_dev integer no" 262.It "user.posix2_char_term integer no" 263.It "user.posix2_fort_dev integer no" 264.It "user.posix2_fort_run integer no" 265.It "user.posix2_localedef integer no" 266.It "user.posix2_sw_dev integer no" 267.It "user.posix2_upe integer no" 268.It "user.stream_max integer no" 269.It "user.tzname_max integer no" 270.It "user.localbase string no" 271.El 272.Sh FILES 273.Bl -tag -width ".In netinet/icmp_var.h" -compact 274.It In sys/sysctl.h 275definitions for top level identifiers, second level kernel and hardware 276identifiers, and user level identifiers 277.It In sys/socket.h 278definitions for second level network identifiers 279.It In sys/gmon.h 280definitions for third level profiling identifiers 281.It In vm/vm_param.h 282definitions for second level virtual memory identifiers 283.It In netinet/in.h 284definitions for third level Internet identifiers and 285fourth level IP identifiers 286.It In netinet/icmp_var.h 287definitions for fourth level ICMP identifiers 288.It In netinet/udp_var.h 289definitions for fourth level UDP identifiers 290.El 291.Sh EXIT STATUS 292.Ex -std 293.Sh EXAMPLES 294For example, to retrieve the maximum number of processes allowed 295in the system, one would use the following request: 296.Pp 297.Dl "sysctl kern.maxproc" 298.Pp 299To set the maximum number of processes allowed 300per uid to 1000, one would use the following request: 301.Pp 302.Dl "sysctl kern.maxprocperuid=1000" 303.Pp 304Information about the system clock rate may be obtained with: 305.Pp 306.Dl "sysctl kern.clockrate" 307.Pp 308Information about the load average history may be obtained with: 309.Pp 310.Dl "sysctl vm.loadavg" 311.Pp 312More variables than these exist, and the best and likely only place 313to search for their deeper meaning is undoubtedly the source where 314they are defined. 315.Sh COMPATIBILITY 316The 317.Fl w 318option has been deprecated and is silently ignored. 319.Sh SEE ALSO 320.Xr sysctl 3 , 321.Xr loader.conf 5 , 322.Xr sysctl.conf 5 , 323.Xr loader 8 324.Sh HISTORY 325A 326.Nm 327utility first appeared in 328.Bx 4.4 . 329.Pp 330In 331.Fx 2.2 , 332.Nm 333was significantly remodeled. 334.Sh BUGS 335The 336.Nm 337utility presently exploits an undocumented interface to the kernel 338.Xr sysctl 9 339facility to traverse the sysctl tree and to retrieve format 340and name information. 341This correct interface is being thought about for the time being. 342