Sysctl
Encyclopedia
Sysctl is an interface for examining and dynamically changing parameters in the BSD and Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

 operating systems. The implementation mechanism in these two systems is very different.

In BSD these parameters are generally objects in a management information base
Management information base
A management information base is a virtual database used for managing the entities in a communications network. Most often associated with the Simple Network Management Protocol , the term is also used more generically in contexts such as in OSI/ISO Network management model...

 (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
Internet Protocol
The Internet Protocol is the principal communications protocol used for relaying datagrams across an internetwork using the Internet Protocol Suite...

 forwarding, security restrictions on the superuser
Superuser
On many computer operating systems, the superuser is a special user account used for system administration. Depending on the operating system, the actual name of this account might be: root, administrator or supervisor....

 (the "securelevel"), or debugging output.

In BSD a system call
System call
In computing, a system call is how a program requests a service from an operating system's kernel. This may include hardware related services , creating and executing new processes, and communicating with integral kernel services...

 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
Booting
In computing, booting is a process that begins when a user turns on a computer system and prepares the computer to perform its normal operations. On modern computers, this typically involves loading and starting an operating system. The boot sequence is the initial set of operations that the...

).

This feature appeared in 4.4BSD. It has the advantage over hardcoded constants that changes to the parameters can be made dynamically without recompiling
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

 the kernel.

In Linux the sysctl interface mechanism is also exported as part of procfs
Procfs
procfs is a special filesystem in UNIX-like operating systems that presents information about processes and other system information in a hierarchical file-like structure, providing a more convenient and standardized method for dynamically accessing process data held in the kernel than traditional...

 under the sys directory. This difference means checking the value of some parameter requires opening a file in a virtual filesystem, reading its contents, parsing them and closing the file. The sysctl system call does exist on Linux, but does not have a wrapping function in glibc and is not recommended for use.

Performance considerations

In BSD the system call is implemented directly in the kernel, as described in the sysctl(3) manual page. In Linux, the sysctl is implemented as a wrapper around file system routines that access contents of files in the /proc directory. The result is that it is much more expensive to use the sysctl interface in Linux. The effect of this can be easily seen with system monitoring tools. On Linux, running top and holding the spacebar to force it to refresh quickly uses large amounts of CPU time, which is not the case on BSD systems. On Linux sysctl interfaces are typically not called repeatedly or frequently in this fashion so this impact is rarely an important consideration.

Examples

When IP forwarding is enabled, the operating system kernel will act as a router. In FreeBSD
FreeBSD
FreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...

, NetBSD
NetBSD
NetBSD is a freely available open source version of the Berkeley Software Distribution Unix operating system. It was the second open source BSD descendant to be formally released, after 386BSD, and continues to be actively developed. The NetBSD project is primarily focused on high quality design,...

, OpenBSD
OpenBSD
OpenBSD is a Unix-like computer operating system descended from Berkeley Software Distribution , a Unix derivative developed at the University of California, Berkeley. It was forked from NetBSD by project leader Theo de Raadt in late 1995...

, DragonFly BSD
DragonFly BSD
DragonFly BSD is a free Unix-like operating system created as a fork of FreeBSD 4.8. Matthew Dillon, an Amiga developer in the late 1980s and early 1990s and a FreeBSD developer between 1994 and 2003, began work on DragonFly BSD in June 2003 and announced it on the FreeBSD mailing lists on July...

, and Darwin
Darwin (operating system)
Darwin is an open source POSIX-compliant computer operating system released by Apple Inc. in 2000. It is composed of code developed by Apple, as well as code derived from NeXTSTEP, BSD, and other free software projects....

/Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...

 the parameter net.inet.ip.forwarding can be set to 1 to enable this behavior. In Linux's emulation of sysctl, the parameter is called net.ipv4.ip_forward.

In most systems, the command 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 parameter=1 can be added/rewritten to the file /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 /boot/loader.conf.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK