2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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 .\" 4. 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.
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
28 .\" @(#)sysctl.3 8.4 (Berkeley) 5/9/95
38 .Nd get or set system information
45 .Fn sysctl "int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "void *newp" "size_t newlen"
47 .Fn sysctlbyname "const char *name" "void *oldp" "size_t *oldlenp" "void *newp" "size_t newlen"
49 .Fn sysctlnametomib "const char *name" "int *mibp" "size_t *sizep"
53 function retrieves system information and allows processes with
54 appropriate privileges to set system information.
55 The information available from
57 consists of integers, strings, and tables.
58 Information may be retrieved and set from the command interface
63 Unless explicitly noted below,
65 returns a consistent snapshot of the data requested.
66 Consistency is obtained by locking the destination
67 buffer into memory so that the data may be copied out without blocking.
70 are serialized to avoid deadlock.
72 The state is described using a ``Management Information Base'' (MIB)
77 length array of integers.
81 function accepts an ASCII representation of the name and internally
82 looks up the integer name vector.
83 Apart from that, it behaves the same
88 The information is copied into the buffer specified by
90 The size of the buffer is given by the location specified by
93 and that location gives the amount of data copied after a successful call
94 and after a call that returns with the error code
96 If the amount of data available is greater
97 than the size of the buffer supplied,
98 the call supplies as much data as fits in the buffer provided
99 and returns with the error code
101 If the old value is not desired,
105 should be set to NULL.
107 The size of the available data can be determined by calling
113 The size of the available data will be returned in the location pointed to by
115 For some operations, the amount of space may change often.
116 For these operations,
117 the system attempts to round up so that the returned size is
118 large enough for a call to return the data shortly thereafter.
122 is set to point to a buffer of length
124 from which the requested value is to be taken.
125 If a new value is not to be set,
127 should be set to NULL and
133 function accepts an ASCII representation of the name,
134 looks up the integer name vector,
135 and returns the numeric representation in the mib array pointed to by
137 The number of elements in the mib array is given by the location specified by
140 and that location gives the number of entries copied after a successful call.
145 may be used in subsequent
147 calls to get the data associated with the requested ASCII name.
148 This interface is intended for use by applications that want to
149 repeatedly request the same variable (the
151 function runs in about a third the time as the same request made via the
155 The top level names are defined with a CTL_ prefix in
158 The next and subsequent levels down are found in the include files
159 listed here, and described in separate sections below.
160 .Bl -column CTLXMACHDEPXXX "Next level namesXXXXXX" -offset indent
161 .It Sy "Name Next level names Description"
162 .It "CTL_DEBUG sys/sysctl.h Debugging"
163 .It "CTL_VFS sys/mount.h File system"
164 .It "CTL_HW sys/sysctl.h Generic CPU, I/O"
165 .It "CTL_KERN sys/sysctl.h High kernel limits"
166 .It "CTL_MACHDEP sys/sysctl.h Machine dependent"
167 .It "CTL_NET sys/socket.h Networking"
168 .It "CTL_USER sys/sysctl.h User-level"
169 .It "CTL_VM sys/resources.h Virtual memory (struct loadavg)"
172 For example, the following retrieves the maximum number of processes allowed
175 .Bd -literal -offset indent -compact
177 size_t len = sizeof(maxproc);
178 sysctlbyname("kern.maxproc", &maxproc, &len, NULL, 0);
181 To retrieve the standard search path for the system utilities:
183 .Bd -literal -offset indent -compact
186 sysctlbyname("user.cs_path", NULL, &len, NULL, 0);
188 sysctlbyname("user.cs_path", p, &len, NULL, 0);
191 A distinguished second level name, VFS_GENERIC,
192 is used to get general information about all file systems.
193 One of its third level identifiers is VFS_MAXTYPENUM
194 that gives the highest valid file system type number.
195 Its other third level identifier is VFS_CONF that
196 returns configuration information about the file system
197 type given as a fourth level identifier (see
199 as an example of its use).
200 The remaining second level identifiers are the
201 file system type number returned by a
203 call or from VFS_CONF.
204 The third level identifiers available for each file system
205 are given in the header file that defines the mount
206 argument structure for that file system.
208 The string and integer information available for the CTL_HW level
210 The changeable column shows whether a process with appropriate
211 privilege may change the value.
212 .Bl -column "xxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxx" -offset indent
213 .It Sy "Name Type Changeable"
214 .It "hw.activecpu int32_t no"
215 .It "hw.byteorder int32_t no"
216 .It "hw.cacheconfig uint64_t[] no"
217 .It "hw.cachelinesize int64_t no"
218 .It "hw.cachesize uint64_t[] no"
219 .It "hw.cpu64bit_capable int32_t no"
220 .It "hw.cpufamily int32_t no"
221 .It "hw.cpufrequency int64_t no"
222 .It "hw.cpufrequency_max int64_t no"
223 .It "hw.cpufrequency_min int64_t no"
224 .It "hw.cpusubtype int32_t no"
225 .It "hw.cputhreadtype int32_t no"
226 .It "hw.cputype int32_t no"
227 .It "hw.l1dcachesize int64_t no"
228 .It "hw.l1icachesize int64_t no"
229 .It "hw.l2cachesize int64_t no"
230 .It "hw.l3cachesize int64_t no"
231 .It "hw.logicalcpu int32_t no"
232 .It "hw.logicalcpu_max int32_t no"
233 .It "hw.machine char[] no"
234 .It "hw.memsize int64_t no"
235 .It "hw.model char[] no"
236 .It "hw.ncpu int32_t no"
237 .It "hw.packages int32_t no"
238 .It "hw.pagesize int64_t no"
239 .It "hw.physicalcpu int32_t no"
240 .It "hw.physicalcpu_max int32_t no"
241 .It "hw.tbfrequency int64_t no"
244 .It Li "hw.byteorder"
245 The byte order (4321 or 1234).
249 The number of cpus. This attribute is deprecated and it is recommended that
250 .Va "hw.logicalcpu" ,
251 .Va "hw.logicalcpu_max" ,
252 .Va "hw.physicalcpu" ,
254 .Va "hw.physicalcpu_max"
256 .It Li "hw.logicalcpu"
257 The number of logical processors available in the current power management mode.
258 .It Li "hw.logicalcpu_max"
259 The maximum number of logical processors that could be available this boot.
260 .It Li "hw.physicalcpu"
261 The number of physical processors available in the current power management mode.
262 .It Li "hw.physicalcpu_max"
263 The maximum number of physical processors that could be available this boot.
265 The software page size in bytes.
268 The string and integer information available for the CTL_KERN level
270 The changeable column shows whether a process with appropriate
271 privilege may change the value.
272 The types of data currently available are process information,
273 system vnodes, the open file entries, routing table entries,
274 virtual memory statistics, load average history, and clock rate
276 .Bl -column "xxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxx" -offset indent
277 .It Sy "Name Type Changeable"
278 .It "kern.argmax int32_t no"
279 .It "kern.bootargs char[] no"
280 .It "kern.boottime struct timeval no"
281 .It "kern.check_openevt int32_t yes"
282 .It "kern.clockrate struct clockinfo no"
283 .It "kern.coredump int32_t yes"
284 .It "kern.corefile char[] yes"
285 .It "kern.flush_cache_on_write int32_t yes"
286 .It "kern.hostid int32_t yes"
287 .It "kern.hostname char[] yes"
288 .It "kern.job_control int32_t no"
289 .It "kern.maxfiles int32_t yes"
290 .It "kern.maxfilesperproc int32_t yes"
291 .It "kern.maxnbuf int32_t yes"
292 .It "kern.maxproc int32_t yes"
293 .It "kern.maxprocperuid int32_t yes"
294 .It "kern.maxvnodes int32_t yes"
295 .It "kern.msgbuf int32_t yes"
296 .It "kern.nbuf int32_t no"
297 .It "kern.netboot int32_t no"
298 .It "kern.ngroups int32_t no"
299 .It "kern.nisdomainname char[] yes"
300 .It "kern.num_files int32_t no"
301 .It "kern.num_tasks int32_t no"
302 .It "kern.num_taskthreads int32_t no"
303 .It "kern.num_threads int32_t no"
304 .It "kern.num_vnodes int32_t no"
305 .It "kern.nx int32_t yes"
306 .It "kern.osrelease char[] no"
307 .It "kern.osrevision int32_t no"
308 .It "kern.ostype char[] no"
309 .It "kern.osversion char[] yes"
310 .It "kern.posix1version int32_t no"
311 .It "kern.procname char[] yes"
312 .It "kern.safeboot int32_t no"
313 .It "kern.saved_ids int32_t no"
314 .It "kern.secure_kernel int32_t no"
315 .It "kern.securelevel int32_t yes"
316 .It "kern.singleuser int32_t no"
317 .It "kern.sleeptime struct timeval no"
318 .It "kern.slide int32_t no"
319 .It "kern.stack_depth_max int32_t no"
320 .It "kern.stack_size int32_t no"
321 .It "kern.sugid_coredump int32_t yes"
322 .It "kern.sugid_scripts int32_t yes"
323 .It "kern.symfile char[] no"
324 .It "kern.usrstack int32_t no"
325 .It "kern.usrstack64 int64_t no"
326 .It "kern.uuid char[] no"
327 .It "kern.version char[] no"
328 .It "kern.waketime struct timeval no"
332 The maximum bytes of argument to
334 .It Li "kern.boottime"
337 structure is returned.
338 This structure contains the time that the system was booted.
339 .It Li "kern.clockrate"
342 structure is returned.
343 This structure contains the clock, statistics clock and profiling clock
344 frequencies, the number of micro-seconds per hz tick and the skew rate.
346 Get or set the host id.
347 .It Li "kern.hostname"
348 Get or set the hostname.
349 .It Li "kern.job_control"
350 Return 1 if job control is available on this system, otherwise 0.
351 .It Li "kern.maxfiles"
352 The maximum number of files that may be open in the system.
353 .It Li "kern.maxfilesperproc"
354 The maximum number of files that may be open for a single process.
355 This limit only applies to processes with an effective uid of nonzero
356 at the time of the open request.
357 Files that have already been opened are not affected if the limit
358 or the effective uid is changed.
359 .It Li "kern.maxproc"
360 The maximum number of concurrent processes the system will allow.
361 .It Li "kern.maxprocperuid"
362 The maximum number of concurrent processes the system will allow
363 for a single effective uid.
364 This limit only applies to processes with an effective uid of nonzero
365 at the time of a fork request.
366 Processes that have already been started are not affected if the limit
368 .It Li "kern.maxvnodes"
369 The maximum number of vnodes available on the system.
370 .It Li "kern.ngroups"
371 The maximum number of supplemental groups.
372 .It Li "kern.nisdomainname"
373 The name of the current YP/NIS domain.
374 .It Li "kern.osrelease"
375 The system release string.
376 .It Li "kern.osrevision"
377 The system revision number.
379 The system type string.
380 .It Li "kern.posix1version"
383 with which the system
385 .It Li "kern.saved_ids"
386 Returns 1 if saved set-group and saved set-user ID is available.
387 .It Li "kern.securelevel"
388 The system security level.
389 This level may be raised by processes with appropriate privilege.
390 It may not be lowered.
391 .It Li "kern.version"
392 The system version string.
395 The set of variables defined is architecture dependent.
396 The following variables are defined for the i386 architecture.
397 .Bl -column "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxx" -offset indent
398 .It Sy "Name Type Changeable"
399 .It "machdep.cpu.address_bits.physical int32_t no"
400 .It "machdep.cpu.address_bits.virtual int32_t no"
401 .It "machdep.cpu.brand int32_t no"
402 .It "machdep.cpu.brand_string char[] no"
403 .It "machdep.cpu.cache.L2_associativity int32_t no"
404 .It "machdep.cpu.cache.linesize int32_t no"
405 .It "machdep.cpu.cache.size int32_t no"
406 .It "machdep.cpu.core_count int32_t no"
407 .It "machdep.cpu.cores_per_package int32_t no"
408 .It "machdep.cpu.extfamily int32_t no"
409 .It "machdep.cpu.extfeature_bits int64_t no"
410 .It "machdep.cpu.extfeatures char[] no"
411 .It "machdep.cpu.extmodel int32_t no"
412 .It "machdep.cpu.family int32_t no"
413 .It "machdep.cpu.feature_bits int64_t no"
414 .It "machdep.cpu.features char[] no"
415 .It "machdep.cpu.leaf7_feature_bits uint32_t no"
416 .It "machdep.cpu.leaf7_features char[] no"
417 .It "machdep.cpu.logical_per_package int32_t no"
418 .It "machdep.cpu.max_basic uint32_t no"
419 .It "machdep.cpu.max_ext uint32_t no"
420 .It "machdep.cpu.microcode_version int32_t no"
421 .It "machdep.cpu.model int32_t no"
422 .It "machdep.cpu.processor_flag int32_t no"
423 .It "machdep.cpu.signature int32_t no"
424 .It "machdep.cpu.stepping int32_t no"
425 .It "machdep.cpu.thread_count int32_t no"
426 .It "machdep.cpu.tlb.data.large int32_t no"
427 .It "machdep.cpu.tlb.data.large_level1 int32_t no"
428 .It "machdep.cpu.tlb.data.small int32_t no"
429 .It "machdep.cpu.tlb.data.small_level1 int32_t no"
430 .It "machdep.cpu.tlb.inst.large int32_t no"
431 .It "machdep.cpu.tlb.inst.small int32_t no"
432 .It "machdep.cpu.tlb.shared int32_t no"
433 .It "machdep.cpu.ucupdate int32_t yes"
434 .It "machdep.cpu.vendor char[] no"
435 .It "machdep.cpu.xsave.extended_state uint32_t no"
436 .It "machdep.tsc.deep_idle_rebase uint32_t yes"
437 .It "machdep.tsc.frequency int64_t no"
438 .It "machdep.tsc.nanotime.generation uint32_t no"
439 .It "machdep.tsc.nanotime.shift uint32_t no"
442 The string and integer information available for the CTL_NET level
444 The changeable column shows whether a process with appropriate
445 privilege may change the value.
446 .Bl -column "Second level nameXXXXXX" "routing messagesXXX" -offset indent
447 .It Sy "Second level name Type Changeable"
448 .It "PF_ROUTE routing messages no"
449 .It "PF_INET IPv4 values yes"
450 .It "PF_INET6 IPv6 values yes"
454 Return the entire routing table or a subset of it.
455 The data is returned as a sequence of routing messages (see
457 for the header file, format and meaning).
458 The length of each message is contained in the message header.
460 The third level name is a protocol number, which is currently always 0.
461 The fourth level name is an address family, which may be set to 0 to
462 select all address families.
463 The fifth, sixth, and seventh level names are as follows:
464 .Bl -column -offset indent "Fifth level Sixth level" "Seventh level"
465 .It Sy "Fifth level Sixth level" Ta Sy "Seventh level"
466 .It "NET_RT_FLAGS rtflags" Ta "None"
467 .It "NET_RT_DUMP None" Ta "None or fib number"
468 .It "NET_RT_IFLIST 0 or if_index" Ta None
469 .It "NET_RT_IFMALIST 0 or if_index" Ta None
470 .It "NET_RT_IFLISTL 0 or if_index" Ta None
475 name returns information about multicast group memberships on all interfaces
476 if 0 is specified, or for the interface specified by
479 Get or set various global information about the IPv4
480 (Internet Protocol version 4).
481 The third level name is the protocol.
482 The fourth level name is the variable name.
483 The currently defined protocols and names are:
484 .Bl -column ProtocolXX VariableXX TypeXX ChangeableXX
485 .It Sy "Protocol Variable Type Changeable"
486 .It "icmp bmcastecho integer yes"
487 .It "icmp maskrepl integer yes"
488 .It "ip forwarding integer yes"
489 .It "ip redirect integer yes"
490 .It "ip ttl integer yes"
491 .It "udp checksum integer yes"
494 The variables are as follows:
496 .It Li icmp.bmcastecho
497 Returns 1 if an ICMP echo request to a broadcast or multicast address is
500 Returns 1 if ICMP network mask requests are to be answered.
502 Returns 1 when IP forwarding is enabled for the host,
503 meaning that the host is acting as a router.
505 Returns 1 when ICMP redirects may be sent by the host.
506 This option is ignored unless the host is routing IP packets,
507 and should normally be enabled on all systems.
509 The maximum time-to-live (hop count) value for an IP packet sourced by
511 This value applies to normal transport protocols, not to ICMP.
513 Returns 1 when UDP checksums are being computed and checked.
514 Disabling UDP checksums is strongly discouraged.
516 For variables net.inet.*.ipsec, please refer to
520 Get or set various global information about the IPv6
521 (Internet Protocol version 6).
522 The third level name is the protocol.
523 The fourth level name is the variable name.
525 For variables net.inet6.* please refer to
527 For variables net.inet6.*.ipsec6, please refer to
531 The string and integer information available for the CTL_USER level
533 The changeable column shows whether a process with appropriate
534 privilege may change the value.
535 .Bl -column "xxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxx" -offset indent
536 .It Sy "Name Type Changeable"
537 .It "user.bc_base_max int32_t no"
538 .It "user.bc_dim_max int32_t no"
539 .It "user.bc_scale_max int32_t no"
540 .It "user.bc_string_max int32_t no"
541 .It "user.coll_weights_max int32_t no"
542 .It "user.cs_path char[] no"
543 .It "user.expr_nest_max int32_t no"
544 .It "user.line_max int32_t no"
545 .It "user.posix2_c_bind int32_t no"
546 .It "user.posix2_c_dev int32_t no"
547 .It "user.posix2_char_term int32_t no"
548 .It "user.posix2_fort_dev int32_t no"
549 .It "user.posix2_fort_run int32_t no"
550 .It "user.posix2_localedef int32_t no"
551 .It "user.posix2_sw_dev int32_t no"
552 .It "user.posix2_upe int32_t no"
553 .It "user.posix2_version int32_t no"
554 .It "user.re_dup_max int32_t no"
555 .It "user.stream_max int32_t no"
556 .It "user.tzname_max int32_t no"
560 .It Li "user.bc_base_max"
561 The maximum ibase/obase values in the
564 .It Li "user.bc_dim_max"
565 The maximum array size in the
568 .It Li "user.bc_scale_max"
569 The maximum scale value in the
572 .It Li "user.bc_string_max"
573 The maximum string length in the
576 .It Li "user.coll_weights_max"
577 The maximum number of weights that can be assigned to any entry of
578 the LC_COLLATE order keyword in the locale definition file.
579 .It Li "user.cs_path"
580 Return a value for the
582 environment variable that finds all the standard utilities.
583 .It Li "user.expr_nest_max"
584 The maximum number of expressions that can be nested within
588 .It Li "user.line_max"
589 The maximum length in bytes of a text-processing utility's input
591 .It Li "user.posix2_c_bind"
592 Return 1 if the system's C-language development facilities support the
593 C-Language Bindings Option, otherwise 0.
594 .It Li "user.posix2_c_dev"
595 Return 1 if the system supports the C-Language Development Utilities Option,
597 .It Li "user.posix2_char_term"
598 Return 1 if the system supports at least one terminal type capable of
599 all operations described in
602 .It Li "user.posix2_fort_dev"
603 Return 1 if the system supports the FORTRAN Development Utilities Option,
605 .It Li "user.posix2_fort_run"
606 Return 1 if the system supports the FORTRAN Runtime Utilities Option,
608 .It Li "user.posix2_localedef"
609 Return 1 if the system supports the creation of locales, otherwise 0.
610 .It Li "user.posix2_sw_dev"
611 Return 1 if the system supports the Software Development Utilities Option,
613 .It Li "user.posix2_upe"
614 Return 1 if the system supports the User Portability Utilities Option,
616 .It Li "user.posix2_version"
619 with which the system attempts to comply.
620 .It Li "user.re_dup_max"
621 The maximum number of repeated occurrences of a regular expression
622 permitted when using interval notation.
623 .It Li "user.stream_max"
624 The minimum maximum number of streams that a process may have open
626 .It Li "user.tzname_max"
627 The minimum maximum number of types supported for the name of a
631 The string and integer information available for the CTL_VM level
633 The changeable column shows whether a process with appropriate
634 privilege may change the value.
635 .Bl -column "xxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxx" -offset indent
636 .It Sy "Name Type Changeable"
637 .It "vm.loadavg struct loadavg no"
638 .It "vm.swapusage struct xsw_usage no"
643 Return the load average history.
644 The returned data consists of a
650 .Bl -tag -width <netinet/icmpXvar.h> -compact
652 definitions for top level identifiers, second level kernel and hardware
653 identifiers, and user level identifiers
655 definitions for second level network identifiers
657 definitions for third level IPv4/IPv6 identifiers and
658 fourth level IPv4/v6 identifiers
659 .It In netinet/icmp_var.h
660 definitions for fourth level ICMP identifiers
661 .It In netinet/icmp6.h
662 definitions for fourth level ICMPv6 identifiers
663 .It In netinet/udp_var.h
664 definitions for fourth level UDP identifiers
667 The following errors may be reported:
676 contains an invalid address.
680 array is less than two or greater than CTL_MAXNAME.
684 is given and its specified length in
686 is too large or too small.
688 The length pointed to by
690 is too short to hold the requested value.
692 The smaller of either the length pointed to by
694 or the estimated size of the returned data exceeds the
695 system limit on locked memory.
699 or a portion of the buffer if the estimated size of the data
700 to be returned is smaller,
701 would cause the process to exceed its per-process locked memory limit.
705 array specifies an intermediate rather than terminal name.
709 array specifies a terminal name, but the actual name is not terminal.
713 array specifies a value that is unknown.
715 An attempt is made to set a read-only value.
717 A process without appropriate privilege attempts to set a value.
726 function first appeared in