]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/gen/sysctl.3
zfs: merge openzfs/zfs@797f55ef1
[FreeBSD/FreeBSD.git] / lib / libc / gen / sysctl.3
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 .\"     @(#)sysctl.3    8.4 (Berkeley) 5/9/95
29 .\"
30 .Dd March 16, 2023
31 .Dt SYSCTL 3
32 .Os
33 .Sh NAME
34 .Nm sysctl ,
35 .Nm sysctlbyname ,
36 .Nm sysctlnametomib
37 .Nd get or set system information
38 .Sh LIBRARY
39 .Lb libc
40 .Sh SYNOPSIS
41 .In sys/sysctl.h
42 .Ft int
43 .Fn sysctl "const int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "const void *newp" "size_t newlen"
44 .Ft int
45 .Fn sysctlbyname "const char *name" "void *oldp" "size_t *oldlenp" "const void *newp" "size_t newlen"
46 .Ft int
47 .Fn sysctlnametomib "const char *name" "int *mibp" "size_t *sizep"
48 .Sh DESCRIPTION
49 The
50 .Fn sysctl
51 function retrieves system information and allows processes with
52 appropriate privileges to set system information.
53 The information available from
54 .Fn sysctl
55 consists of integers, strings, and tables.
56 Information may be retrieved and set from the command interface
57 using the
58 .Xr sysctl 8
59 utility.
60 .Pp
61 Unless explicitly noted below,
62 .Fn sysctl
63 returns a consistent snapshot of the data requested.
64 Consistency is obtained by locking the destination
65 buffer into memory so that the data may be copied out without blocking.
66 Calls to
67 .Fn sysctl
68 are serialized to avoid deadlock.
69 .Pp
70 The state is described using a ``Management Information Base'' (MIB)
71 style name, listed in
72 .Fa name ,
73 which is a
74 .Fa namelen
75 length array of integers.
76 .Pp
77 The
78 .Fn sysctlbyname
79 function accepts an ASCII representation of the name and internally
80 looks up the integer name vector.
81 Apart from that, it behaves the same
82 as the standard
83 .Fn sysctl
84 function.
85 .Pp
86 The information is copied into the buffer specified by
87 .Fa oldp .
88 The size of the buffer is given by the location specified by
89 .Fa oldlenp
90 before the call,
91 and that location gives the amount of data copied after a successful call
92 and after a call that returns with the error code
93 .Er ENOMEM .
94 If the amount of data available is greater
95 than the size of the buffer supplied,
96 the call supplies as much data as fits in the buffer provided
97 and returns with the error code
98 .Er ENOMEM .
99 If the old value is not desired,
100 .Fa oldp
101 and
102 .Fa oldlenp
103 should be set to NULL.
104 .Pp
105 The size of the available data can be determined by calling
106 .Fn sysctl
107 with the
108 .Dv NULL
109 argument for
110 .Fa oldp .
111 The size of the available data will be returned in the location pointed to by
112 .Fa oldlenp .
113 For some operations, the amount of space may change often.
114 For these operations,
115 the system attempts to round up so that the returned size is
116 large enough for a call to return the data shortly thereafter.
117 .Pp
118 To set a new value,
119 .Fa newp
120 is set to point to a buffer of length
121 .Fa newlen
122 from which the requested value is to be taken.
123 If a new value is not to be set,
124 .Fa newp
125 should be set to NULL and
126 .Fa newlen
127 set to 0.
128 .Pp
129 The
130 .Fn sysctlnametomib
131 function accepts an ASCII representation of the name,
132 looks up the integer name vector,
133 and returns the numeric representation in the mib array pointed to by
134 .Fa mibp .
135 The number of elements in the mib array is given by the location specified by
136 .Fa sizep
137 before the call,
138 and that location gives the number of entries copied after a successful call.
139 The resulting
140 .Fa mib
141 and
142 .Fa size
143 may be used in subsequent
144 .Fn sysctl
145 calls to get the data associated with the requested ASCII name.
146 This interface is intended for use by applications that want to
147 repeatedly request the same variable (the
148 .Fn sysctl
149 function runs in about a third the time as the same request made via the
150 .Fn sysctlbyname
151 function).
152 The
153 .Fn sysctlnametomib
154 function is also useful for fetching mib prefixes and then adding
155 a final component.
156 For example, to fetch process information
157 for processes with pid's less than 100:
158 .Pp
159 .Bd -literal -offset indent -compact
160 int i, mib[4];
161 size_t len;
162 struct kinfo_proc kp;
163
164 /* Fill out the first three components of the mib */
165 len = 4;
166 sysctlnametomib("kern.proc.pid", mib, &len);
167
168 /* Fetch and print entries for pid's < 100 */
169 for (i = 0; i < 100; i++) {
170         mib[3] = i;
171         len = sizeof(kp);
172         if (sysctl(mib, 4, &kp, &len, NULL, 0) == -1)
173                 perror("sysctl");
174         else if (len > 0)
175                 printkproc(&kp);
176 }
177 .Ed
178 .Pp
179 The top level names are defined with a CTL_ prefix in
180 .In sys/sysctl.h ,
181 and are as follows.
182 The next and subsequent levels down are found in the include files
183 listed here, and described in separate sections below.
184 .Bl -column CTLXMACHDEPXXX "Next Level NamesXXXXXX" -offset indent
185 .It Sy Name Ta Sy Next Level Names Ta Sy Description
186 .It Dv CTL_DEBUG Ta In sys/sysctl.h Ta Debugging
187 .It Dv CTL_VFS Ta In sys/mount.h Ta File system
188 .It Dv CTL_HW Ta In sys/sysctl.h Ta Generic CPU, I/O
189 .It Dv CTL_KERN Ta In sys/sysctl.h Ta High kernel limits
190 .It Dv CTL_MACHDEP Ta In sys/sysctl.h Ta Machine dependent
191 .It Dv CTL_NET Ta In sys/socket.h Ta Networking
192 .It Dv CTL_USER Ta In sys/sysctl.h Ta User-level
193 .It Dv CTL_VM Ta In vm/vm_param.h Ta Virtual memory
194 .El
195 .Pp
196 For example, the following retrieves the maximum number of processes allowed
197 in the system:
198 .Pp
199 .Bd -literal -offset indent -compact
200 int mib[2], maxproc;
201 size_t len;
202
203 mib[0] = CTL_KERN;
204 mib[1] = KERN_MAXPROC;
205 len = sizeof(maxproc);
206 sysctl(mib, 2, &maxproc, &len, NULL, 0);
207 .Ed
208 .Pp
209 To retrieve the standard search path for the system utilities:
210 .Pp
211 .Bd -literal -offset indent -compact
212 int mib[2];
213 size_t len;
214 char *p;
215
216 mib[0] = CTL_USER;
217 mib[1] = USER_CS_PATH;
218 sysctl(mib, 2, NULL, &len, NULL, 0);
219 p = malloc(len);
220 sysctl(mib, 2, p, &len, NULL, 0);
221 .Ed
222 .Ss CTL_DEBUG
223 The debugging variables vary from system to system.
224 A debugging variable may be added or deleted without need to recompile
225 .Fn sysctl
226 to know about it.
227 Each time it runs,
228 .Fn sysctl
229 gets the list of debugging variables from the kernel and
230 displays their current values.
231 The system defines twenty
232 .Pq Vt "struct ctldebug"
233 variables named
234 .Va debug0
235 through
236 .Va debug19 .
237 They are declared as separate variables so that they can be
238 individually initialized at the location of their associated variable.
239 The loader prevents multiple use of the same variable by issuing errors
240 if a variable is initialized in more than one place.
241 For example, to export the variable
242 .Va dospecialcheck
243 as a debugging variable, the following declaration would be used:
244 .Pp
245 .Bd -literal -offset indent -compact
246 int dospecialcheck = 1;
247 struct ctldebug debug5 = { "dospecialcheck", &dospecialcheck };
248 .Ed
249 .Ss CTL_VFS
250 A distinguished second level name, VFS_GENERIC,
251 is used to get general information about all file systems.
252 One of its third level identifiers is VFS_MAXTYPENUM
253 that gives the highest valid file system type number.
254 Its other third level identifier is VFS_CONF that
255 returns configuration information about the file system
256 type given as a fourth level identifier (see
257 .Xr getvfsbyname 3
258 as an example of its use).
259 The remaining second level identifiers are the
260 file system type number returned by a
261 .Xr statfs 2
262 call or from VFS_CONF.
263 The third level identifiers available for each file system
264 are given in the header file that defines the mount
265 argument structure for that file system.
266 .Ss CTL_HW
267 The string and integer information available for the CTL_HW level
268 is detailed below.
269 The changeable column shows whether a process with appropriate
270 privilege may change the value.
271 .Bl -column "Second Level Name" integerXXX Changeable -offset indent
272 .It Sy Second Level Name Ta Sy Type Ta Sy Changeable
273 .It Dv HW_MACHINE Ta string Ta no
274 .It Dv HW_MODEL Ta string Ta no
275 .It Dv HW_NCPU Ta integer Ta no
276 .It Dv HW_BYTEORDER Ta integer Ta no
277 .It Dv HW_PHYSMEM Ta integer Ta no
278 .It Dv HW_USERMEM Ta integer Ta no
279 .It Dv HW_PAGESIZE Ta integer Ta no
280 .\".It Dv HW_DISKNAMES Ta integer Ta no
281 .\".It Dv HW_DISKSTATS Ta integer Ta no
282 .It Dv HW_FLOATINGPT Ta integer Ta no
283 .It Dv HW_MACHINE_ARCH Ta string Ta no
284 .It Dv HW_REALMEM Ta integer Ta no
285 .It Dv HW_AVAILPAGES Ta integer Ta no
286 .El
287 .Bl -tag -width 6n
288 .It Li HW_MACHINE
289 The machine class.
290 .It Li HW_MODEL
291 The machine model
292 .It Li HW_NCPU
293 The number of cpus.
294 .It Li HW_BYTEORDER
295 The byteorder (4321 or 1234).
296 .It Li HW_PHYSMEM
297 Amount of physical memory (in bytes), minus the amount used by the kernel,
298 pre-loaded modules, and (on x86) the dcons buffer.
299 .It Li HW_USERMEM
300 Amount of memory (in bytes) which is not wired.
301 .It Li HW_PAGESIZE
302 The software page size.
303 .\".It Fa HW_DISKNAMES
304 .\".It Fa HW_DISKSTATS
305 .It Li HW_FLOATINGPT
306 Nonzero if the floating point support is in hardware.
307 .It Li HW_MACHINE_ARCH
308 The machine dependent architecture type.
309 .It Li HW_REALMEM
310 Amount of memory (in bytes) reported by the firmware.
311 That value is sometimes not sane; in that case, the kernel reports the max
312 memory address instead.
313 .It Li HW_AVAILPAGES
314 The same value as
315 .Li HW_PHYSMEM ,
316 measured in pages rather than bytes.
317 .El
318 .Ss CTL_KERN
319 The string and integer information available for the CTL_KERN level
320 is detailed below.
321 The changeable column shows whether a process with appropriate
322 privilege may change the value.
323 The types of data currently available are process information,
324 system vnodes, the open file entries, routing table entries,
325 virtual memory statistics, load average history, and clock rate
326 information.
327 .Bl -column "KERNXMAXFILESPERPROCXXX" "struct clockrateXXX" -offset indent
328 .It Sy Second Level Name Ta Sy Type Ta Sy Changeable
329 .It Dv KERN_ARGMAX Ta integer Ta no
330 .It Dv KERN_BOOTFILE Ta string Ta yes
331 .It Dv KERN_BOOTTIME Ta struct timeval Ta no
332 .It Dv KERN_CLOCKRATE Ta struct clockinfo Ta no
333 .It Dv KERN_FILE Ta struct xfile Ta no
334 .It Dv KERN_HOSTID Ta integer Ta yes
335 .It Dv KERN_HOSTUUID Ta string Ta yes
336 .It Dv KERN_HOSTNAME Ta string Ta yes
337 .It Dv KERN_JOB_CONTROL Ta integer Ta no
338 .It Dv KERN_MAXFILES Ta integer Ta yes
339 .It Dv KERN_MAXFILESPERPROC Ta integer Ta yes
340 .It Dv KERN_MAXPROC Ta integer Ta no
341 .It Dv KERN_MAXPROCPERUID Ta integer Ta yes
342 .It Dv KERN_MAXVNODES Ta integer Ta yes
343 .It Dv KERN_NGROUPS Ta integer Ta no
344 .It Dv KERN_NISDOMAINNAME Ta string Ta yes
345 .It Dv KERN_OSRELDATE Ta integer Ta no
346 .It Dv KERN_OSRELEASE Ta string Ta no
347 .It Dv KERN_OSREV Ta integer Ta no
348 .It Dv KERN_OSTYPE Ta string Ta no
349 .It Dv KERN_POSIX1 Ta integer Ta no
350 .It Dv KERN_PROC Ta node Ta not applicable
351 .It Dv KERN_QUANTUM Ta integer Ta yes
352 .It Dv KERN_SAVED_IDS Ta integer Ta no
353 .It Dv KERN_SECURELVL Ta integer Ta raise only
354 .It Dv KERN_UPDATEINTERVAL Ta integer Ta no
355 .It Dv KERN_VERSION Ta string Ta no
356 .El
357 .Bl -tag -width 6n
358 .It Li KERN_ARGMAX
359 The maximum bytes of argument to
360 .Xr execve 2 .
361 .It Li KERN_BOOTFILE
362 The full pathname of the file from which the kernel was loaded.
363 .It Li KERN_BOOTTIME
364 A
365 .Va struct timeval
366 structure is returned.
367 This structure contains the time that the system was booted.
368 .It Li KERN_CLOCKRATE
369 A
370 .Va struct clockinfo
371 structure is returned.
372 This structure contains the clock, statistics clock and profiling clock
373 frequencies, the number of micro-seconds per hz tick and the skew rate.
374 .It Li KERN_FILE
375 Return the entire file table.
376 The returned data consists of an array of
377 .Va struct xfile ,
378 whose size depends on the current number of such objects in the system.
379 .It Li KERN_HOSTID
380 Get or set the host ID.
381 .It Li KERN_HOSTUUID
382 Get or set the host's universally unique identifier (UUID).
383 .It Li KERN_HOSTNAME
384 Get or set the hostname.
385 .It Li KERN_JOB_CONTROL
386 Return 1 if job control is available on this system, otherwise 0.
387 .It Li KERN_MAXFILES
388 The maximum number of files that may be open in the system.
389 .It Li KERN_MAXFILESPERPROC
390 The maximum number of files that may be open for a single process.
391 This limit only applies to processes with an effective uid of nonzero
392 at the time of the open request.
393 Files that have already been opened are not affected if the limit
394 or the effective uid is changed.
395 .It Li KERN_MAXPROC
396 The maximum number of concurrent processes the system will allow.
397 .It Li KERN_MAXPROCPERUID
398 The maximum number of concurrent processes the system will allow
399 for a single effective uid.
400 This limit only applies to processes with an effective uid of nonzero
401 at the time of a fork request.
402 Processes that have already been started are not affected if the limit
403 is changed.
404 .It Li KERN_MAXVNODES
405 The maximum number of vnodes available on the system.
406 .It Li KERN_NGROUPS
407 The maximum number of supplemental groups.
408 .It Li KERN_NISDOMAINNAME
409 The name of the current YP/NIS domain.
410 .It Li KERN_OSRELDATE
411 The kernel release version in the format
412 .Ar M Ns Ar mm Ns Ar R Ns Ar xx ,
413 where
414 .Ar M
415 is the major version,
416 .Ar mm
417 is the two digit minor version,
418 .Ar R
419 is 0 if release branch, otherwise 1,
420 and
421 .Ar xx
422 is updated when the available APIs change.
423 .Pp
424 The userland release version is available from
425 .In osreldate.h ;
426 parse this file if you need to get the release version of
427 the currently installed userland.
428 .It Li KERN_OSRELEASE
429 The system release string.
430 .It Li KERN_OSREV
431 The system revision string.
432 .It Li KERN_OSTYPE
433 The system type string.
434 .It Li KERN_POSIX1
435 The version of
436 .St -p1003.1
437 with which the system
438 attempts to comply.
439 .It Li KERN_PROC
440 Return selected information about specific running processes.
441 .Pp
442 For the following names, an array of
443 .Va struct kinfo_proc
444 structures is returned,
445 whose size depends on the current number of such objects in the system.
446 .Bl -column "Third Level NameXXXXXX" "Fourth LevelXXXXXX" -offset indent
447 .It Sy Third Level Name Ta Sy Fourth Level
448 .It Dv KERN_PROC_ALL Ta None
449 .It Dv KERN_PROC_PID Ta A process ID
450 .It Dv KERN_PROC_PGRP Ta A process group
451 .It Dv KERN_PROC_TTY Ta A tty device
452 .It Dv KERN_PROC_UID Ta A user ID
453 .It Dv KERN_PROC_RUID Ta A real user ID
454 .El
455 .Pp
456 If the third level name is
457 .Dv KERN_PROC_ARGS
458 then the command line argument
459 array is returned in a flattened form, i.e., zero-terminated arguments
460 follow each other.
461 The total size of array is returned.
462 It is also possible for a process to set its own process title this way.
463 If the third level name is
464 .Dv KERN_PROC_PATHNAME ,
465 the path of the
466 process' text file is stored.
467 For
468 .Dv KERN_PROC_PATHNAME ,
469 a process ID of
470 .Li \-1
471 implies the current process.
472 .Bl -column "Third Level NameXXXXXX" "Fourth LevelXXXXXX" -offset indent
473 .It Sy Third Level Name Ta Sy Fourth Level
474 .It Dv KERN_PROC_ARGS Ta "A process ID"
475 .It Dv KERN_PROC_PATHNAME Ta "A process ID"
476 .El
477 .It Li KERN_QUANTUM
478 The maximum period of time, in microseconds, for which a process is allowed
479 to run without being preempted if other processes are in the run queue.
480 .It Li KERN_SAVED_IDS
481 Returns 1 if saved set-group and saved set-user ID is available.
482 .It Li KERN_SECURELVL
483 The system security level.
484 This level may be raised by processes with appropriate privilege.
485 It may not be lowered.
486 .It Li KERN_VERSION
487 The system version string.
488 .El
489 .Ss CTL_NET
490 The string and integer information available for the CTL_NET level
491 is detailed below.
492 The changeable column shows whether a process with appropriate
493 privilege may change the value.
494 .Bl -column "Second Level NameXXXXXX" "routing messagesXXX" -offset indent
495 .It Sy Second Level Name Ta Sy Type Ta Sy Changeable
496 .It Dv PF_ROUTE Ta routing messages Ta no
497 .It Dv PF_INET Ta IPv4 values Ta yes
498 .It Dv PF_INET6 Ta IPv6 values Ta yes
499 .El
500 .Bl -tag -width 6n
501 .It Li PF_ROUTE
502 Return the entire routing table or a subset of it.
503 The data is returned as a sequence of routing messages (see
504 .Xr route 4
505 for the header file, format and meaning).
506 The length of each message is contained in the message header.
507 .Pp
508 The third level name is a protocol number, which is currently always 0.
509 The fourth level name is an address family, which may be set to 0 to
510 select all address families.
511 The fifth, sixth, and seventh level names are as follows:
512 .Bl -column -offset indent "Fifth Level" "Sixth Level" "Seventh Level"
513 .It Sy Fifth level Ta Sy Sixth Level Ta Sy Seventh Level
514 .It Dv NET_RT_FLAGS Ta rtflags Ta None
515 .It Dv NET_RT_DUMP Ta None Ta None or fib number
516 .It Dv NET_RT_IFLIST Ta 0 or if_index Ta None
517 .It Dv NET_RT_IFMALIST Ta 0 or if_index Ta None
518 .It Dv NET_RT_IFLISTL Ta 0 or if_index Ta None
519 .It Dv NET_RT_NHOPS Ta None Ta fib number
520 .El
521 .Pp
522 The
523 .Dv NET_RT_IFMALIST
524 name returns information about multicast group memberships on all interfaces
525 if 0 is specified, or for the interface specified by
526 .Va if_index .
527 .Pp
528 The
529 .Dv NET_RT_IFLISTL
530 is like
531 .Dv NET_RT_IFLIST ,
532 just returning message header structs with additional fields allowing the
533 interface to be extended without breaking binary compatibility.
534 The
535 .Dv NET_RT_IFLISTL
536 uses 'l' versions of the message header structures:
537 .Va struct if_msghdrl
538 and
539 .Va struct ifa_msghdrl .
540 .Pp
541 .Dv NET_RT_NHOPS
542 returns all nexthops for specified address family in given fib.
543 .It Li PF_INET
544 Get or set various global information about the IPv4
545 (Internet Protocol version 4).
546 The third level name is the protocol.
547 The fourth level name is the variable name.
548 The currently defined protocols and names are:
549 .Bl -column ProtocolXX VariableXX TypeXX ChangeableXX
550 .It Sy Protocol Ta Sy Variable Ta Sy Type Ta Sy Changeable
551 .It icmp Ta bmcastecho Ta integer Ta yes
552 .It icmp Ta maskrepl Ta integer Ta yes
553 .It ip Ta forwarding Ta integer Ta yes
554 .It ip Ta redirect Ta integer Ta yes
555 .It ip Ta ttl Ta integer Ta yes
556 .It udp Ta checksum Ta integer Ta yes
557 .El
558 .Pp
559 The variables are as follows:
560 .Bl -tag -width 6n
561 .It Li icmp.bmcastecho
562 Returns 1 if an ICMP echo request to a broadcast or multicast address is
563 to be answered.
564 .It Li icmp.maskrepl
565 Returns 1 if ICMP network mask requests are to be answered.
566 .It Li ip.forwarding
567 Returns 1 when IP forwarding is enabled for the host,
568 meaning that the host is acting as a router.
569 .It Li ip.redirect
570 Returns 1 when ICMP redirects may be sent by the host.
571 This option is ignored unless the host is routing IP packets,
572 and should normally be enabled on all systems.
573 .It Li ip.ttl
574 The maximum time-to-live (hop count) value for an IP packet sourced by
575 the system.
576 This value applies to normal transport protocols, not to ICMP.
577 .It Li udp.checksum
578 Returns 1 when UDP checksums are being computed and checked.
579 Disabling UDP checksums is strongly discouraged.
580 .Pp
581 For variables net.inet.*.ipsec, please refer to
582 .Xr ipsec 4 .
583 .El
584 .It Li PF_INET6
585 Get or set various global information about the IPv6
586 (Internet Protocol version 6).
587 The third level name is the protocol.
588 The fourth level name is the variable name.
589 .Pp
590 For variables net.inet6.* please refer to
591 .Xr inet6 4 .
592 For variables net.inet6.*.ipsec6, please refer to
593 .Xr ipsec 4 .
594 .El
595 .Ss CTL_USER
596 The string and integer information available for the CTL_USER level
597 is detailed below.
598 The changeable column shows whether a process with appropriate
599 privilege may change the value.
600 .Bl -column "USER_COLL_WEIGHTS_MAXXXX" "integerXXX" -offset indent
601 .It Sy Second Level Name Ta Sy Type Ta Sy Changeable
602 .It Dv USER_BC_BASE_MAX Ta integer Ta no
603 .It Dv USER_BC_DIM_MAX Ta integer Ta no
604 .It Dv USER_BC_SCALE_MAX Ta integer Ta no
605 .It Dv USER_BC_STRING_MAX Ta integer Ta no
606 .It Dv USER_COLL_WEIGHTS_MAX Ta integer Ta no
607 .It Dv USER_CS_PATH Ta string Ta no
608 .It Dv USER_EXPR_NEST_MAX Ta integer Ta no
609 .It Dv USER_LINE_MAX Ta integer Ta no
610 .It Dv USER_LOCALBASE Ta string Ta no
611 .It Dv USER_POSIX2_CHAR_TERM Ta integer Ta no
612 .It Dv USER_POSIX2_C_BIND Ta integer Ta no
613 .It Dv USER_POSIX2_C_DEV Ta integer Ta no
614 .It Dv USER_POSIX2_FORT_DEV Ta integer Ta no
615 .It Dv USER_POSIX2_FORT_RUN Ta integer Ta no
616 .It Dv USER_POSIX2_LOCALEDEF Ta integer Ta no
617 .It Dv USER_POSIX2_SW_DEV Ta integer Ta no
618 .It Dv USER_POSIX2_UPE Ta integer Ta no
619 .It Dv USER_POSIX2_VERSION Ta integer Ta no
620 .It Dv USER_RE_DUP_MAX Ta integer Ta no
621 .It Dv USER_STREAM_MAX Ta integer Ta no
622 .It Dv USER_TZNAME_MAX Ta integer Ta no
623 .El
624 .Bl -tag -width 6n
625 .It Li USER_BC_BASE_MAX
626 The maximum ibase/obase values in the
627 .Xr bc 1
628 utility.
629 .It Li USER_BC_DIM_MAX
630 The maximum array size in the
631 .Xr bc 1
632 utility.
633 .It Li USER_BC_SCALE_MAX
634 The maximum scale value in the
635 .Xr bc 1
636 utility.
637 .It Li USER_BC_STRING_MAX
638 The maximum string length in the
639 .Xr bc 1
640 utility.
641 .It Li USER_COLL_WEIGHTS_MAX
642 The maximum number of weights that can be assigned to any entry of
643 the LC_COLLATE order keyword in the locale definition file.
644 .It Li USER_CS_PATH
645 Return a value for the
646 .Ev PATH
647 environment variable that finds all the standard utilities.
648 .It Li USER_EXPR_NEST_MAX
649 The maximum number of expressions that can be nested within
650 parenthesis by the
651 .Xr expr 1
652 utility.
653 .It Li USER_LINE_MAX
654 The maximum length in bytes of a text-processing utility's input
655 line.
656 .It Li USER_LOCALBASE
657 Return the value of localbase that has been compiled into system utilities
658 that need to have access to resources provided by a port or package.
659 .It Li USER_POSIX2_CHAR_TERM
660 Return 1 if the system supports at least one terminal type capable of
661 all operations described in
662 .St -p1003.2 ,
663 otherwise 0.
664 .It Li USER_POSIX2_C_BIND
665 Return 1 if the system's C-language development facilities support the
666 C-Language Bindings Option, otherwise 0.
667 .It Li USER_POSIX2_C_DEV
668 Return 1 if the system supports the C-Language Development Utilities Option,
669 otherwise 0.
670 .It Li USER_POSIX2_FORT_DEV
671 Return 1 if the system supports the FORTRAN Development Utilities Option,
672 otherwise 0.
673 .It Li USER_POSIX2_FORT_RUN
674 Return 1 if the system supports the FORTRAN Runtime Utilities Option,
675 otherwise 0.
676 .It Li USER_POSIX2_LOCALEDEF
677 Return 1 if the system supports the creation of locales, otherwise 0.
678 .It Li USER_POSIX2_SW_DEV
679 Return 1 if the system supports the Software Development Utilities Option,
680 otherwise 0.
681 .It Li USER_POSIX2_UPE
682 Return 1 if the system supports the User Portability Utilities Option,
683 otherwise 0.
684 .It Li USER_POSIX2_VERSION
685 The version of
686 .St -p1003.2
687 with which the system attempts to comply.
688 .It Li USER_RE_DUP_MAX
689 The maximum number of repeated occurrences of a regular expression
690 permitted when using interval notation.
691 .It Li USER_STREAM_MAX
692 The minimum maximum number of streams that a process may have open
693 at any one time.
694 .It Li USER_TZNAME_MAX
695 The minimum maximum number of types supported for the name of a
696 timezone.
697 .El
698 .Ss CTL_VM
699 The string and integer information available for the CTL_VM level
700 is detailed below.
701 The changeable column shows whether a process with appropriate
702 privilege may change the value.
703 .Bl -column "Second Level NameXXXXXX" "struct loadavgXXX" -offset indent
704 .It Sy Second Level Name Ta Sy Type Ta Sy Changeable
705 .It Dv VM_LOADAVG Ta struct loadavg Ta no
706 .It Dv VM_TOTAL Ta struct vmtotal Ta no
707 .It Dv VM_SWAPPING_ENABLED Ta integer Ta maybe
708 .It Dv VM_V_FREE_MIN Ta integer Ta yes
709 .It Dv VM_V_FREE_RESERVED Ta integer Ta yes
710 .It Dv VM_V_FREE_TARGET Ta integer Ta yes
711 .It Dv VM_V_INACTIVE_TARGET Ta integer Ta yes
712 .It Dv VM_V_PAGEOUT_FREE_MIN Ta integer Ta yes
713 .It Dv VM_OVERCOMMIT Ta integer Ta yes
714 .El
715 .Bl -tag -width 6n
716 .It Li VM_LOADAVG
717 Return the load average history.
718 The returned data consists of a
719 .Va struct loadavg .
720 .It Li VM_TOTAL
721 Return the system wide virtual memory statistics.
722 The returned data consists of a
723 .Va struct vmtotal .
724 .It Li VM_SWAPPING_ENABLED
725 1 if process swapping is enabled or 0 if disabled.
726 This variable is
727 permanently set to 0 if the kernel was built with swapping disabled.
728 .It Li VM_V_FREE_MIN
729 Minimum amount of memory (cache memory plus free memory)
730 required to be available before a process waiting on memory will be
731 awakened.
732 .It Li VM_V_FREE_RESERVED
733 Processes will awaken the pageout daemon and wait for memory if the
734 number of free and cached pages drops below this value.
735 .It Li VM_V_FREE_TARGET
736 The total amount of free memory (including cache memory) that the
737 pageout daemon tries to maintain.
738 .It Li VM_V_INACTIVE_TARGET
739 The desired number of inactive pages that the pageout daemon should
740 achieve when it runs.
741 Inactive pages can be quickly inserted into
742 process address space when needed.
743 .It Li VM_V_PAGEOUT_FREE_MIN
744 If the amount of free and cache memory falls below this value, the
745 pageout daemon will enter "memory conserving mode" to avoid deadlock.
746 .It Li VM_OVERCOMMIT
747 Overcommit behaviour, as described in
748 .Xr tuning 7 .
749 .El
750 .Sh RETURN VALUES
751 .Rv -std
752 .Sh FILES
753 .Bl -tag -width <netinet/icmpXvar.h> -compact
754 .It In sys/sysctl.h
755 definitions for top level identifiers, second level kernel and hardware
756 identifiers, and user level identifiers
757 .It In sys/socket.h
758 definitions for second level network identifiers
759 .It In sys/gmon.h
760 definitions for third level profiling identifiers
761 .It In vm/vm_param.h
762 definitions for second level virtual memory identifiers
763 .It In netinet/in.h
764 definitions for third level IPv4/IPv6 identifiers and
765 fourth level IPv4/v6 identifiers
766 .It In netinet/icmp_var.h
767 definitions for fourth level ICMP identifiers
768 .It In netinet/icmp6.h
769 definitions for fourth level ICMPv6 identifiers
770 .It In netinet/udp_var.h
771 definitions for fourth level UDP identifiers
772 .El
773 .Sh ERRORS
774 The following errors may be reported:
775 .Bl -tag -width Er
776 .It Bq Er EFAULT
777 The buffer
778 .Fa name ,
779 .Fa oldp ,
780 .Fa newp ,
781 or length pointer
782 .Fa oldlenp
783 contains an invalid address.
784 .It Bq Er EINVAL
785 The
786 .Fa name
787 array is less than two or greater than CTL_MAXNAME.
788 .It Bq Er EINVAL
789 A non-null
790 .Fa newp
791 is given and its specified length in
792 .Fa newlen
793 is too large or too small.
794 .It Bq Er ENOMEM
795 The length pointed to by
796 .Fa oldlenp
797 is too short to hold the requested value.
798 .It Bq Er ENOMEM
799 The smaller of either the length pointed to by
800 .Fa oldlenp
801 or the estimated size of the returned data exceeds the
802 system limit on locked memory.
803 .It Bq Er ENOMEM
804 Locking the buffer
805 .Fa oldp ,
806 or a portion of the buffer if the estimated size of the data
807 to be returned is smaller,
808 would cause the process to exceed its per-process locked memory limit.
809 .It Bq Er ENOTDIR
810 The
811 .Fa name
812 array specifies an intermediate rather than terminal name.
813 .It Bq Er EISDIR
814 The
815 .Fa name
816 array specifies a terminal name, but the actual name is not terminal.
817 .It Bq Er ENOENT
818 The
819 .Fa name
820 array specifies a value that is unknown.
821 .It Bq Er EPERM
822 An attempt is made to set a read-only value.
823 .It Bq Er EPERM
824 A process without appropriate privilege attempts to set a value.
825 .El
826 .Sh SEE ALSO
827 .Xr confstr 3 ,
828 .Xr kvm 3 ,
829 .Xr sysconf 3 ,
830 .Xr sysctl 8
831 .Sh HISTORY
832 The
833 .Fn sysctl
834 function first appeared in
835 .Bx 4.4 .