]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/sysctl.2
sched_setattr.2: tfix
[thirdparty/man-pages.git] / man2 / sysctl.2
CommitLineData
fea681da
MK
1.\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
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.
7.\"
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.
c13182ef 12.\"
fea681da
MK
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
19.\" professionally.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da
MK
24.\"
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.
29.\"
6b621d05 30.TH SYSCTL 2 2020-02-09 "Linux" "Linux Programmer's Manual"
fea681da
MK
31.SH NAME
32sysctl \- read/write system parameters
33.SH SYNOPSIS
16718a1c 34.nf
fea681da 35.B #include <unistd.h>
fea681da 36.B #include <linux/sysctl.h>
68e4db0a 37.PP
fea681da 38.BI "int _sysctl(struct __sysctl_args *" args );
16718a1c 39.fi
fea681da 40.SH DESCRIPTION
5dc3d7b7 41.B This system call no longer exists on current kernels!
5f06e2ff 42See NOTES.
efeece04 43.PP
fea681da 44The
e511ffb6 45.BR _sysctl ()
c13182ef
MK
46call reads and/or writes kernel parameters.
47For example, the hostname,
48or the maximum number of open files.
49The argument has the form
fea681da 50.PP
088a639b 51.in +4n
b8302363 52.EX
fea681da 53struct __sysctl_args {
90b36ddd
MK
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 */
fea681da 61};
b8302363 62.EE
90b36ddd 63.in
fea681da
MK
64.PP
65This call does a search in a tree structure, possibly resembling
66a directory tree under
8478ee02 67.IR /proc/sys ,
fea681da
MK
68and if the requested item is found calls some appropriate routine
69to read or modify the value.
47297adb 70.SH RETURN VALUE
fea681da 71Upon successful completion,
e511ffb6 72.BR _sysctl ()
c13182ef
MK
73returns 0.
74Otherwise, a value of \-1 is returned and
fea681da
MK
75.I errno
76is set to indicate the error.
77.SH ERRORS
78.TP
cbb57e74
MK
79.BR EACCES ", " EPERM
80No search permission for one of the encountered "directories",
81or no read permission where
82.I oldval
83was nonzero, or no write permission where
84.I newval
85was nonzero.
86.TP
fea681da
MK
87.B EFAULT
88The invocation asked for the previous value by setting
89.I oldval
90non-NULL, but allowed zero room in
91.IR oldlenp .
92.TP
93.B ENOTDIR
94.I name
95was not found.
5dc3d7b7
MK
96.SH VERSIONS
97This system call first appeared in Linux 1.3.57.
98It was removed in Linux 5.5.
47297adb 99.SH CONFORMING TO
8382f16d 100This call is Linux-specific, and should not be used in programs
fea681da 101intended to be portable.
c13182ef
MK
102It originated in
1034.4BSD.
104Only Linux has the
fea681da 105.I /proc/sys
b14d4aa5 106mirror, and the object naming schemes differ between Linux and 4.4BSD,
fea681da 107but the declaration of the
2777b1ca 108.BR sysctl ()
fea681da 109function is the same in both.
f5b03186 110.SH NOTES
5dc3d7b7
MK
111Use of this system call was long discouraged:
112since Linux 2.6.24,
113uses of this system call result in warnings in the kernel log,
114and in Linux 5.5, the system call was finally removed.
115Use the
fea681da
MK
116.I /proc/sys
117interface instead.
efeece04 118.PP
5dc3d7b7
MK
119Note that on older kernels where this system call still exists,
120it is available only if the kernel was configured with the
28474c20
MK
121.B CONFIG_SYSCTL_SYSCALL
122option.
5dc3d7b7
MK
123Furthermore,
124glibc does not provide a wrapper for this system call,
125necessitating the use of
126.BR syscall (2).
127.PP
3efbc18c
MK
128.SH BUGS
129The object names vary between kernel versions,
130making this system call worthless for applications.
ef17a8a1 131.PP
fea681da 132Not all available objects are properly documented.
ef17a8a1 133.PP
fea681da
MK
134It is not yet possible to change operating system by writing to
135.IR /proc/sys/kernel/ostype .
2b2581ee 136.SH EXAMPLE
207050fa 137.EX
c12fd10d
MK
138#define _GNU_SOURCE
139#include <unistd.h>
140#include <sys/syscall.h>
141#include <string.h>
142#include <stdio.h>
143#include <stdlib.h>
2b2581ee
MK
144#include <linux/sysctl.h>
145
c12fd10d 146int _sysctl(struct __sysctl_args *args );
2b2581ee 147
2b2581ee
MK
148#define OSNAMESZ 100
149
2b2581ee
MK
150int
151main(void)
152{
c12fd10d
MK
153 struct __sysctl_args args;
154 char osname[OSNAMESZ];
155 size_t osnamelth;
156 int name[] = { CTL_KERN, KERN_OSTYPE };
157
158 memset(&args, 0, sizeof(struct __sysctl_args));
159 args.name = name;
160 args.nlen = sizeof(name)/sizeof(name[0]);
161 args.oldval = osname;
162 args.oldlenp = &osnamelth;
988db661 163
2b2581ee 164 osnamelth = sizeof(osname);
988db661 165
29059a65 166 if (syscall(SYS__sysctl, &args) == \-1) {
c12fd10d
MK
167 perror("_sysctl");
168 exit(EXIT_FAILURE);
169 }
d1a71985 170 printf("This machine is running %*s\en", osnamelth, osname);
2b2581ee
MK
171 exit(EXIT_SUCCESS);
172}
207050fa 173.EE
47297adb 174.SH SEE ALSO
fea681da 175.BR proc (5)