1SYSCTL(2) Linux Programmer's Manual SYSCTL(2)
2
3
4
6 sysctl - read/write system parameters
7
9 #include <unistd.h>
10 #include <linux/sysctl.h>
11
12 int _sysctl(struct __sysctl_args *args);
13
15 Do not use this system call! See NOTES.
16
17 The _sysctl() call reads and/or writes kernel parameters. For example,
18 the hostname, or the maximum number of open files. The argument has
19 the form
20
21 struct __sysctl_args {
22 int *name; /* integer vector describing variable */
23 int nlen; /* length of this vector */
24 void *oldval; /* 0 or address where to store old value */
25 size_t *oldlenp; /* available room for old value,
26 overwritten by actual size of old value */
27 void *newval; /* 0 or address of new value */
28 size_t newlen; /* size of new value */
29 };
30
31 This call does a search in a tree structure, possibly resembling a
32 directory tree under /proc/sys, and if the requested item is found
33 calls some appropriate routine to read or modify the value.
34
36 Upon successful completion, _sysctl() returns 0. Otherwise, a value of
37 -1 is returned and errno is set to indicate the error.
38
40 EFAULT The invocation asked for the previous value by setting oldval
41 non-NULL, but allowed zero room in oldlenp.
42
43 ENOTDIR
44 name was not found.
45
46 EPERM No search permission for one of the encountered "directories",
47 or no read permission where oldval was non-zero, or no write
48 permission where newval was non-zero.
49
51 This call is Linux-specific, and should not be used in programs
52 intended to be portable. A sysctl() call has been present in Linux
53 since version 1.3.57. It originated in 4.4BSD. Only Linux has the
54 /proc/sys mirror, and the object naming schemes differ between Linux
55 and 4.4BSD, but the declaration of the sysctl() function is the same in
56 both.
57
59 Glibc does not provide a wrapper for this system call; call it using
60 syscall(2).
61
62 Or rather... don't call it: use of this system call has long been dis‐
63 couraged, and it is so unloved that it is likely to disappear in a
64 future kernel version. Remove it from your programs now; use the
65 /proc/sys interface instead.
66
68 The object names vary between kernel versions, making this system call
69 worthless for applications.
70
71 Not all available objects are properly documented.
72
73 It is not yet possible to change operating system by writing to
74 /proc/sys/kernel/ostype.
75
77 #define _GNU_SOURCE
78 #include <unistd.h>
79 #include <sys/syscall.h>
80 #include <string.h>
81 #include <stdio.h>
82 #include <stdlib.h>
83 #include <linux/sysctl.h>
84
85 int _sysctl(struct __sysctl_args *args );
86
87 #define OSNAMESZ 100
88
89 int
90 main(void)
91 {
92 struct __sysctl_args args;
93 char osname[OSNAMESZ];
94 size_t osnamelth;
95 int name[] = { CTL_KERN, KERN_OSTYPE };
96
97 memset(&args, 0, sizeof(struct __sysctl_args));
98 args.name = name;
99 args.nlen = sizeof(name)/sizeof(name[0]);
100 args.oldval = osname;
101 args.oldlenp = &osnamelth;
102
103 osnamelth = sizeof(osname);
104
105 if (syscall(SYS__sysctl, &args) == -1) {
106 perror("_sysctl");
107 exit(EXIT_FAILURE);
108 }
109 printf("This machine is running %*s\n", osnamelth, osname);
110 exit(EXIT_SUCCESS);
111 }
112
114 proc(5)
115
117 This page is part of release 3.22 of the Linux man-pages project. A
118 description of the project, and information about reporting bugs, can
119 be found at http://www.kernel.org/doc/man-pages/.
120
121
122
123Linux 2008-11-20 SYSCTL(2)