sysctl is a tool for examining and changing kernel parameters at runtime on linux based systems. In
order to change the kernel parameters at run time, it makes use of procfs. In other words sysctl makes
this possible via virtual process file system mounted at /proc/ during boot.
Why it is called virtual file system?
“The files and directories of the /proc filesystem are virtual” because the data is not actually stored on
any sort of permanent storage like a hard disk; instead, the directories, files, and data within them are
created dynamically in memory from raw kernel data whenever you attempt to read them.
In a more straight & simple answer: this data is not associated with any block device but exists only in
Which commands internally uses this information?
Number of linux commands such as ps, top, pstree, etc rely on this virtual filesystem for information.
How can I make use of sysctl function to see all the kernel settings currently in use?
To get a quick overview of all settings configurable in the /proc/sys/ directory, type the /sbin/sysctl -a
command as root. This creates a large, comprehensive list. In order to view the list page by page, you
can use the 'less' command with pipe as shown in the example below.
[root@redhatcentos /]# sysctl -a | less
A small portion of which looks something like the following:
net.ipv4.route.min_delay = 2
kernel.sysrq = 0
kernel.sem = 250 32000 32 128
For quick testing of the new values that you want to alter or modify, you can either use 'sysctl'
command Or even 'echo' to assign values to writable files in the /proc/sys/ directory.
For instance using the ‘echo’ command:
[root@redhatcentos /]# echo 1 > /proc/sys/kernel/sysrq
[root@redhatcentos /]# cat /proc/sys/kernel/sysrq
The equivalent sysctl command is as follows:
[root@redhatcentos /]# sysctl -w kernel.sysrq=1
kernel.sysrq = 1
This is temporary: While quickly setting single values like this in /proc/sys/ is helpful during testing, this
method does not work as well on a production system as special settings within /proc/sys/ are lost when
the machine is rebooted. To preserve custom settings, add them to the /etc/sysctl.conf file.
This is permanent: Each time the system boots, the init program runs the /etc/rc.d/rc.sysinit script. This
script contains a command to execute sysctl using /etc/sysctl.conf to determine the values passed to the
kernel. Therefore any values added to /etc/sysctl.conf therefore take effect each time the system boots.
Why did we need this in the first place?
Modern operating system usually segregates virtual memory into kernel space and user space. Kernel
space is strictly reserved for running the kernel, device drivers and kernel extensions. In most operating
systems, kernel memory is never swapped out to disk. User space is the memory area where all user
mode applications work and this memory can be swapped out when necessary.
A user application cannot access kernel space directly and similarly kernel code cannot access the user
space without checking whether the page is present in memory or swapped out. Even though these can
not access each other directly, user and kernel space can communicate with each other using variety of
ways and one of which is what we discussed above -called 'sysctl'.