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