1 .\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" Written 11 April 1996 by Andries Brouwer <aeb@cwi.nl>
24 .\" 960412: Added comments from Stephen Tweedie
25 .\" Modified Tue Oct 22 22:28:41 1996 by Eric S. Raymond <esr@thyrsus.com>
26 .\" Modified Mon Jan 5 20:31:04 1998 by aeb.
28 .TH SYSCTL 2 1996-04-11 "Linux 1.3.85" "Linux Programmer's Manual"
30 sysctl \- read/write system parameters
33 .B #include <unistd.h>
35 .B #include <linux/unistd.h>
37 .B #include <linux/sysctl.h>
41 .B _syscall1(int, _sysctl, struct __sysctl_args *, args)
42 /* Using \fBsyscall\fP(2) may be preferable; see \fBintro\fP(2) */
44 .BI "int _sysctl(struct __sysctl_args *" args );
49 call reads and/or writes kernel parameters.
50 For example, the hostname,
51 or the maximum number of open files.
52 The argument has the form
55 struct __sysctl_args {
56 int *name; /* integer vector describing variable */
57 int nlen; /* length of this vector */
58 void *oldval; /* 0 or address where to store old value */
59 size_t *oldlenp; /* available room for old value,
60 overwritten by actual size of old value */
61 void *newval; /* 0 or address of new value */
62 size_t newlen; /* size of new value */
66 This call does a search in a tree structure, possibly resembling
67 a directory tree under
69 and if the requested item is found calls some appropriate routine
70 to read or modify the value.
73 #include <linux/unistd.h>
74 #include <linux/types.h>
75 #include <linux/sysctl.h>
77 _syscall1(int, _sysctl, struct __sysctl_args *, args);
78 int sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
79 void *newval, size_t newlen)
81 struct __sysctl_args args = { name, nlen, oldval, oldlenp,
83 return _sysctl(&args);
86 #define SIZE(x) sizeof(x)/sizeof(x[0])
89 char osname[OSNAMESZ];
91 int name[] = { CTL_KERN, KERN_OSTYPE };
96 osnamelth = sizeof(osname);
97 if (sysctl(name, SIZE(name), osname, &osnamelth, 0, 0))
100 printf("This machine is running %*s\en", osnamelth, osname);
105 Upon successful completion,
108 Otherwise, a value of \-1 is returned and
110 is set to indicate the error.
114 The invocation asked for the previous value by setting
116 non-NULL, but allowed zero room in
124 No search permission for one of the encountered `directories',
125 or no read permission where
127 was non-zero, or no write permission where
131 This call is Linux specific, and should not be used in programs
132 intended to be portable.
135 call has been present in Linux since version 1.3.57.
140 mirror, and the object naming schemes differ between Linux and 4.4BSD,
141 but the declaration of the
143 function is the same in both.
145 The object names vary between kernel versions.
146 THIS MAKES THIS SYSTEM CALL WORTHLESS FOR APPLICATIONS.
151 Not all available objects are properly documented.
153 It is not yet possible to change operating system by writing to
154 .IR /proc/sys/kernel/ostype .