xref: /freebsd/sbin/sysctl/sysctl.8 (revision 5e3190f700637fcfc1a52daeaa4a031fdd2557c7)
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 August 18, 2023
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
198and
199.Xr security 7 .
200.Pp
201The changeable column indicates whether a process with appropriate
202privilege can change the value.
203String and integer values can be set using
204.Nm .
205.Bl -column security.bsd.unprivileged_read_msgbuf integerxxx
206.It Sy "Name	Type	Changeable"
207.It "kern.ostype	string	no"
208.It "kern.osrelease	string	no"
209.It "kern.osrevision	integer	no"
210.It "kern.version	string	no"
211.It "kern.maxvnodes	integer	yes"
212.It "kern.maxproc	integer	no"
213.It "kern.maxprocperuid	integer	yes"
214.It "kern.maxfiles	integer	yes"
215.It "kern.maxfilesperproc	integer	yes"
216.It "kern.argmax	integer	no"
217.It "kern.securelevel	integer	raise only"
218.It "kern.hostname	string	yes"
219.It "kern.hostid	integer	yes"
220.It "kern.clockrate	struct	no"
221.It "kern.posix1version	integer	no"
222.It "kern.ngroups	integer	no"
223.It "kern.job_control	integer	no"
224.It "kern.saved_ids	integer	no"
225.It "kern.boottime	struct	no"
226.It "kern.domainname	string	yes"
227.It "kern.filedelay	integer	yes"
228.It "kern.dirdelay	integer	yes"
229.It "kern.metadelay	integer	yes"
230.It "kern.osreldate	integer	no"
231.It "kern.bootfile	string	yes"
232.It "kern.corefile	string	yes"
233.It "kern.logsigexit	integer	yes"
234.It "security.bsd.suser_enabled	integer	yes"
235.It "security.bsd.see_other_uids	integer	yes"
236.It "security.bsd.see_other_gids	integer	yes"
237.It "security.bsd.see_jail_proc	integer	yes"
238.It "security.bsd.unprivileged_proc_debug	integer	yes"
239.It "security.bsd.unprivileged_read_msgbuf	integer	yes"
240.It "vm.loadavg	struct	no"
241.It "hw.machine	string	no"
242.It "hw.model	string	no"
243.It "hw.ncpu	integer	no"
244.It "hw.byteorder	integer	no"
245.It "hw.physmem	integer	no"
246.It "hw.usermem	integer	no"
247.It "hw.pagesize	integer	no"
248.It "hw.floatingpoint	integer	no"
249.It "hw.machine_arch	string	no"
250.It "hw.realmem	integer	no"
251.It "machdep.adjkerntz	integer	yes"
252.It "machdep.disable_rtc_set	integer	yes"
253.It "machdep.guessed_bootdev	string	no"
254.It "user.cs_path	string	no"
255.It "user.bc_base_max	integer	no"
256.It "user.bc_dim_max	integer	no"
257.It "user.bc_scale_max	integer	no"
258.It "user.bc_string_max	integer	no"
259.It "user.coll_weights_max	integer	no"
260.It "user.expr_nest_max	integer	no"
261.It "user.line_max	integer	no"
262.It "user.re_dup_max	integer	no"
263.It "user.posix2_version	integer	no"
264.It "user.posix2_c_bind	integer	no"
265.It "user.posix2_c_dev	integer	no"
266.It "user.posix2_char_term	integer	no"
267.It "user.posix2_fort_dev	integer	no"
268.It "user.posix2_fort_run	integer	no"
269.It "user.posix2_localedef	integer	no"
270.It "user.posix2_sw_dev	integer	no"
271.It "user.posix2_upe	integer	no"
272.It "user.stream_max	integer	no"
273.It "user.tzname_max	integer	no"
274.It "user.localbase	string	no"
275.El
276.Sh FILES
277.Bl -tag -width ".In netinet/icmp_var.h" -compact
278.It In sys/sysctl.h
279definitions for top level identifiers, second level kernel and hardware
280identifiers, and user level identifiers
281.It In sys/socket.h
282definitions for second level network identifiers
283.It In sys/gmon.h
284definitions for third level profiling identifiers
285.It In vm/vm_param.h
286definitions for second level virtual memory identifiers
287.It In netinet/in.h
288definitions for third level Internet identifiers and
289fourth level IP identifiers
290.It In netinet/icmp_var.h
291definitions for fourth level ICMP identifiers
292.It In netinet/udp_var.h
293definitions for fourth level UDP identifiers
294.El
295.Sh EXIT STATUS
296.Ex -std
297.Sh EXAMPLES
298For example, to retrieve the maximum number of processes allowed
299in the system, one would use the following request:
300.Pp
301.Dl "sysctl kern.maxproc"
302.Pp
303To set the maximum number of processes allowed
304per uid to 1000, one would use the following request:
305.Pp
306.Dl "sysctl kern.maxprocperuid=1000"
307.Pp
308Information about the system clock rate may be obtained with:
309.Pp
310.Dl "sysctl kern.clockrate"
311.Pp
312Information about the load average history may be obtained with:
313.Pp
314.Dl "sysctl vm.loadavg"
315.Pp
316More variables than these exist, and the best and likely only place
317to search for their deeper meaning is undoubtedly the source where
318they are defined.
319.Sh COMPATIBILITY
320The
321.Fl w
322option has been deprecated and is silently ignored.
323.Sh SEE ALSO
324.Xr sysctl 3 ,
325.Xr loader.conf 5 ,
326.Xr sysctl.conf 5 ,
327.Xr security 7,
328.Xr loader 8
329.Sh HISTORY
330A
331.Nm
332utility first appeared in
333.Bx 4.4 .
334.Pp
335In
336.Fx 2.2 ,
337.Nm
338was significantly remodeled.
339.Sh BUGS
340The
341.Nm
342utility presently exploits an undocumented interface to the kernel
343.Xr sysctl 9
344facility to traverse the sysctl tree and to retrieve format
345and name information.
346This correct interface is being thought about for the time being.
347