Sysctl

{{Short description|Unix-like software that manages kernel attributes}}

{{Distinguish|systemctl}}

{{Multiple issues|

{{Primary sources|date=March 2015}}

{{More citations needed|date=November 2011}}

}}

{{Lowercase title}}

{{Infobox software

| name = sysctl

| screenshot = Example of sysctl on Linux screenshot.png

| screenshot size =

| caption = Applying sysctl in a Linux system

| developer =

| latest release version =

| latest release date =

| genre = System configuration

| license =

| website =

| operating_system = Unix-like (BSD)

| programming_language = C

}}

sysctl is a software mechanism in some Unix-like operating systems that reads and modifies the attributes of the system kernel such as its version number, maximum limits, and security settings. It is available both as a system call for compiled programs, and an administrator command for interactive use and scripting. Linux additionally exposes sysctl as a virtual file system.

BSD

In BSD, these parameters are generally objects in a management information base (MIB) that describe tunable limits such as the size of a shared memory segment, the number of threads the operating system will use as an NFS client, or the maximum number of processes on the system; or describe, enable or disable behaviors such as IP forwarding, security restrictions on the superuser (the "securelevel"), or debugging output.

In OpenBSD and DragonFly BSD, sysctl is also used as the transport layer for the hw.sensors framework for hardware monitoring, whereas NetBSD uses the ioctl system call for its sysmon envsys counterpart. Both sysctl and ioctl are the two system calls which can be used to add extra functionality to the kernel without adding yet another system call; for example, in 2004 with OpenBSD 3.6, when the tcpdrop utility was introduced, sysctl was used as the underlying system call. In FreeBSD, although there is no sensors framework, the individual temperature and other sensors are still commonly exported through the sysctl tree through Newbus, for example, as is the case with the aibs(4) driver that's available in all the 4 BSD systems, including FreeBSD.

In BSD, a system call or system call wrapper is usually provided for use by programs, as well as an administrative program and a configuration file (for setting the tunable parameters when the system boots).

This feature first appeared in 4.4BSD. It has the advantage over hardcoded constants that changes to the parameters can be made dynamically without recompiling the kernel.

Historically, although kernel variables themselves could be modified through sysctl, the elements comprising the MIB of the sysctl tree were hardcoded at compile time, and as of 2019, it's mostly still the case in OpenBSD (with some exceptions like hw.sensors, which manages and provides its own dynamic subtree). FreeBSD has had "sysctl internal magic" for dynamic sysctl tree management since 1995; NetBSD has had its own implementation of a dynamic sysctl tree since December 2003.

Linux

In Linux, the sysctl interface mechanism is also exported as part of procfs under the {{mono|/proc/sys}} directory (not to be confused with Sysfs). This difference means checking the value of some parameter requires opening a file in a virtual file system, reading its contents, parsing them and closing the file. The sysctl system call does exist on Linux, but it has been deprecated and does not have a wrapper function in glibc; it is usually unavailable due to many distributions configuring the kernel without CONFIG_SYSCTL_SYSCALL; so it is not recommended for use.{{cite web

| url=http://man7.org/linux/man-pages/man2/sysctl.2.html

| title=sysctl(2): read/write system parameters

| publisher=man7.org

| date=2017-09-15

| access-date=2018-01-04}}

Examples

When IP forwarding is enabled, the operating system kernel will act as a router. In FreeBSD, NetBSD, OpenBSD, DragonFly BSD, and Darwin/Mac OS X, the parameter {{mono|net.inet.ip.forwarding}} can be set to {{mono|1}} to enable this behavior. In Linux, the parameter is called {{mono|net.ipv4.ip_forward}}.

In most systems, the command {{mono|1=sysctl -w parameter=1}} will enable a certain behavior. This will persist until the next reboot. If the behavior should be enabled whenever the system boots, the line {{mono|1=parameter=1}} can be added/rewritten to the file {{mono|/etc/sysctl.conf}}. Additionally, some sysctl variables cannot be modified after the system is booted. These variables (depending on the variable, the version and flavor of BSD) need to either be set statically in the kernel at compile time or set in {{mono|/boot/loader.conf}}.

See also

{{Portal

| Computer programming

| Linux

}}

References

{{Reflist

|refs =

{{cite web

|url= http://bxr.su/o/usr.sbin/tcpdrop/tcpdrop.c

|author = Markus Friedl |date= 2004

|title = tcpdrop.c

|website= BSD Cross Reference

|publisher= OpenBSD

}}

  • {{cite book |section=tcpdrop — drop a TCP connection |title=OpenBSD manual page server |url=http://man.openbsd.org/tcpdrop.8}}

{{cite web

|url= http://www.onlamp.com/lpt/a/5302

|title= OpenBSD 3.6 Live

|author= Federico Biancuzzi

|website= ONLamp |publisher= O'Reilly Media

|date= 2004-10-28 |archive-url= https://web.archive.org/web/20041029232336/http://www.onlamp.com/lpt/a/5302

|access-date=2019-03-20

|archive-date= 2004-10-29

}}

{{cite web

|url= http://bxr.su/n/share/man/man7/sysctl.7

|title= sysctl(7) — system information variables

|website= BSD Cross Reference

|publisher = NetBSD

}}

{{Cite conference

|author= Constantine A. Murenin |date= 2007-04-17

|url = http://sensors.cnst.su/IEEE_ICNSC_2007

|title= Generalised Interfacing with Microprocessor System Hardware Monitors

|conference= Proceedings of 2007 IEEE International Conference on Networking, Sensing and Control, 15–17 April 2007.

|location= London, United Kingdom

|publisher=IEEE

|pages = 901–906 |doi = 10.1109/ICNSC.2007.372901 |isbn = 978-1-4244-1076-7

|id = IEEE ICNSC 2007, pp. 901—906.

}}

{{Cite conference

|author1= Constantine A. Murenin

|author2= Raouf Boutaba

|author2-link= Raouf Boutaba

|date= 2009-03-17

|url= http://www.openbsd.org/papers/asiabsdcon2009-sensors-paper.pdf

|section= 8.3. Sensors framework in FreeBSD CVS

|title= OpenBSD Hardware Sensors Framework.

|conference= AsiaBSDCon 2009 Proceedings, 12–15 March 2009

|location= Tokyo University of Science, Tokyo, Japan

|publication-date= 2009-03-14

|archive-url= https://web.archive.org/web/20100620015220/http://openbsd.org/papers/asiabsdcon2009-sensors-paper.pdf

|archive-date= 2010-06-20

|url-status= bot: unknown

|access-date= 2019-03-04

}}

{{cite thesis

|degree= MMath

|author= Constantine A. Murenin |date= 2010-05-21

|section = 8.3. Sensors framework in FreeBSD CVS

|title= OpenBSD Hardware Sensors — Environmental Monitoring and Fan Control.

|location= University of Waterloo |publisher= UWSpace

|url = http://cnst.su/MMathCS |hdl = 10012/5234

|id = Document ID: ab71498b6b1a60ff817b29d56997a418.

}}

{{cite web

|url= http://bxr.su/FreeBSD/sys/dev/acpi_support/atk0110.c

|title= aibs(4) — ASUSTeK AI Booster ACPI ATK0110 voltage, temperature and fan sensor

|date= 2010

|website= BSD Cross Reference

|publisher= FreeBSD

}}

  • {{cite book |section=aibs -- ASUSTeK AI Booster ACPI ATK0110 voltage, temperature and fan sensor |title=FreeBSD Manual Pages |url=https://www.freebsd.org/cgi/man.cgi?query=aibs&sektion=4&manpath=FreeBSD+8.2-RELEASE}}

}}