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
32 .B #include <unistd.h>
34 .B #include <linux/unistd.h>
36 .B #include <linux/sysctl.h>
40 .B _syscall1(int, _sysctl, struct __sysctl_args *, args)
42 .BI "int _sysctl(struct __sysctl_args *" args );
46 call reads and/or writes kernel parameters. For example, the hostname,
47 or the maximum number of open files. The argument has the form
50 struct __sysctl_args {
51 int *name; /* integer vector describing variable */
52 int nlen; /* length of this vector */
53 void *oldval; /* 0 or address where to store old value */
54 size_t *oldlenp; /* available room for old value,
55 overwritten by actual size of old value */
56 void *newval; /* 0 or address of new value */
57 size_t newlen; /* size of new value */
61 This call does a search in a tree structure, possibly resembling
62 a directory tree under
64 and if the requested item is found calls some appropriate routine
65 to read or modify the value.
69 #include <linux/unistd.h>
70 #include <linux/types.h>
71 #include <linux/sysctl.h>
73 _syscall1(int, _sysctl, struct __sysctl_args *, args);
74 int sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
75 void *newval, size_t newlen)
77 struct __sysctl_args args={name,nlen,oldval,oldlenp,newval,newlen};
78 return _sysctl(&args);
81 #define SIZE(x) sizeof(x)/sizeof(x[0])
84 char osname[OSNAMESZ];
86 int name[] = { CTL_KERN, KERN_OSTYPE };
89 osnamelth = sizeof(osname);
90 if (sysctl(name, SIZE(name), osname, &osnamelth, 0, 0))
93 printf("This machine is running %*s\en", osnamelth, osname);
99 Upon successful completion,
101 returns 0. Otherwise, a value of \-1 is returned and
103 is set to indicate the error.
107 The invocation asked for the previous value by setting
109 non-NULL, but allowed zero room in
117 No search permission for one of the encountered `directories',
118 or no read permission where
120 was nonzero, or no write permission where
124 This call is Linux-specific, and should not be used in programs
125 intended to be portable.
128 call has been present in Linux since version 1.3.57. It originated in
129 4.4BSD. Only Linux has the
131 mirror, and the object naming schemes differ between Linux and BSD 4.4,
132 but the declaration of the
134 function is the same in both.
136 The object names vary between kernel versions.
137 THIS MAKES THIS SYSTEM CALL WORTHLESS FOR APPLICATIONS.
142 Not all available objects are properly documented.
144 It is not yet possible to change operating system by writing to
145 .IR /proc/sys/kernel/ostype .