1 .\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\" Written 11 April 1996 by Andries Brouwer <aeb@cwi.nl>
6 .\" 960412: Added comments from Stephen Tweedie
7 .\" Modified Tue Oct 22 22:28:41 1996 by Eric S. Raymond <esr@thyrsus.com>
8 .\" Modified Mon Jan 5 20:31:04 1998 by aeb.
10 .TH SYSCTL 2 2022-09-17 "Linux man-pages (unreleased)"
12 sysctl \- read/write system parameters
15 .B #include <unistd.h>
16 .B #include <linux/sysctl.h>
18 .BI "[[deprecated]] int _sysctl(struct __sysctl_args *" args );
21 .B This system call no longer exists on current kernels!
26 call reads and/or writes kernel parameters.
27 For example, the hostname,
28 or the maximum number of open files.
29 The argument has the form
33 struct __sysctl_args {
34 int *name; /* integer vector describing variable */
35 int nlen; /* length of this vector */
36 void *oldval; /* 0 or address where to store old value */
37 size_t *oldlenp; /* available room for old value,
38 overwritten by actual size of old value */
39 void *newval; /* 0 or address of new value */
40 size_t newlen; /* size of new value */
45 This call does a search in a tree structure, possibly resembling
46 a directory tree under
48 and if the requested item is found calls some appropriate routine
49 to read or modify the value.
51 Upon successful completion,
54 Otherwise, a value of \-1 is returned and
56 is set to indicate the error.
60 No search permission for one of the encountered "directories",
61 or no read permission where
63 was nonzero, or no write permission where
68 The invocation asked for the previous value by setting
70 non-NULL, but allowed zero room in
77 This system call first appeared in Linux 1.3.57.
78 It was removed in Linux 5.5; glibc support was removed in version 2.32.
80 This call is Linux-specific, and should not be used in programs
81 intended to be portable.
86 mirror, and the object naming schemes differ between Linux and 4.4BSD,
87 but the declaration of the
89 function is the same in both.
91 Use of this system call was long discouraged:
93 uses of this system call result in warnings in the kernel log,
94 and in Linux 5.5, the system call was finally removed.
99 Note that on older kernels where this system call still exists,
100 it is available only if the kernel was configured with the
101 .B CONFIG_SYSCTL_SYSCALL
103 Furthermore, glibc does not provide a wrapper for this system call,
104 necessitating the use of
107 The object names vary between kernel versions,
108 making this system call worthless for applications.
110 Not all available objects are properly documented.
112 It is not yet possible to change operating system by writing to
113 .IR /proc/sys/kernel/ostype .
115 .\" SRC BEGIN (sysctl.c)
121 #include <sys/syscall.h>
124 #include <linux/sysctl.h>
126 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
128 int _sysctl(struct __sysctl_args *args);
135 int name[] = { CTL_KERN, KERN_OSTYPE };
136 char osname[OSNAMESZ];
138 struct __sysctl_args args;
140 memset(&args, 0, sizeof(args));
142 args.nlen = ARRAY_SIZE(name);
143 args.oldval = osname;
144 args.oldlenp = &osnamelth;
146 osnamelth = sizeof(osname);
148 if (syscall(SYS__sysctl, &args) == \-1) {
152 printf("This machine is running %*s\en", (int) osnamelth, osname);