1 .\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Written 11 April 1996 by Andries Brouwer <aeb@cwi.nl>
26 .\" 960412: Added comments from Stephen Tweedie
27 .\" Modified Tue Oct 22 22:28:41 1996 by Eric S. Raymond <esr@thyrsus.com>
28 .\" Modified Mon Jan 5 20:31:04 1998 by aeb.
30 .TH SYSCTL 2 2021-03-22 "Linux" "Linux Programmer's Manual"
32 sysctl \- read/write system parameters
35 .B #include <unistd.h>
36 .B #include <linux/sysctl.h>
38 .BI "int _sysctl(struct __sysctl_args *" args );
41 .B This system call no longer exists on current kernels!
46 call reads and/or writes kernel parameters.
47 For example, the hostname,
48 or the maximum number of open files.
49 The argument has the form
53 struct __sysctl_args {
54 int *name; /* integer vector describing variable */
55 int nlen; /* length of this vector */
56 void *oldval; /* 0 or address where to store old value */
57 size_t *oldlenp; /* available room for old value,
58 overwritten by actual size of old value */
59 void *newval; /* 0 or address of new value */
60 size_t newlen; /* size of new value */
65 This call does a search in a tree structure, possibly resembling
66 a directory tree under
68 and if the requested item is found calls some appropriate routine
69 to read or modify the value.
71 Upon successful completion,
74 Otherwise, a value of \-1 is returned and
76 is set to indicate the error.
80 No search permission for one of the encountered "directories",
81 or no read permission where
83 was nonzero, or no write permission where
88 The invocation asked for the previous value by setting
90 non-NULL, but allowed zero room in
97 This system call first appeared in Linux 1.3.57.
98 It was removed in Linux 5.5; glibc support was removed in version 2.32.
100 This call is Linux-specific, and should not be used in programs
101 intended to be portable.
106 mirror, and the object naming schemes differ between Linux and 4.4BSD,
107 but the declaration of the
109 function is the same in both.
111 Use of this system call was long discouraged:
113 uses of this system call result in warnings in the kernel log,
114 and in Linux 5.5, the system call was finally removed.
119 Note that on older kernels where this system call still exists,
120 it is available only if the kernel was configured with the
121 .B CONFIG_SYSCTL_SYSCALL
123 Furthermore, glibc does not provide a wrapper for this system call,
124 necessitating the use of
127 The object names vary between kernel versions,
128 making this system call worthless for applications.
130 Not all available objects are properly documented.
132 It is not yet possible to change operating system by writing to
133 .IR /proc/sys/kernel/ostype .
138 #include <sys/syscall.h>
142 #include <linux/sysctl.h>
144 int _sysctl(struct __sysctl_args *args );
151 struct __sysctl_args args;
152 char osname[OSNAMESZ];
154 int name[] = { CTL_KERN, KERN_OSTYPE };
156 memset(&args, 0, sizeof(args));
158 args.nlen = sizeof(name)/sizeof(name[0]);
159 args.oldval = osname;
160 args.oldlenp = &osnamelth;
162 osnamelth = sizeof(osname);
164 if (syscall(SYS__sysctl, &args) == \-1) {
168 printf("This machine is running %*s\en", osnamelth, osname);