xref: /csrg-svn/lib/libc/gen/sysctl.3 (revision 58401)
1.\" Copyright (c) 1993 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.roff%
5.\"
6.\"	@(#)sysctl.3	6.1 (Berkeley) 03/02/93
7.\"
8.Dd ""
9.Dt SYSCTL 2
10.Os
11.Sh NAME
12.Nm sysctl
13.Nd get or set kernel state
14.Sh SYNOPSIS
15.Fd #include <sys/sysctl.h>
16.Ft int
17.Fn sysctl "int *name" "u_int namelen" "void *old" "u_int *oldlenp" "void *new" "u_int newlen"
18.Sh DESCRIPTION
19The
20.Fn sysctl
21function retrieves kernel state and allows processes with
22appropriate privilege to set kernel state.
23The state to be set is described using a ``MIB'' style name,
24described in a
25.Fa namelen
26length array of integers pointed to by
27.Fa name .
28The top level names are defined with a CTL_ prefix in
29.Pa <sys/sysctl.h> .
30The next levels down are found in the files given in the ``FILES''
31section of this manual page.
32.Pp
33To retrieve a value,
34.Fa old
35is set to point to a buffer
36into which the requested value is to be placed.
37The length of the buffer is given in the location pointed to by
38.Fa oldlenp .
39The size of the returned value is put in the location pointed to by
40.Fa oldlenp .
41The size of the requested value can be determined by calling
42.Fn sysctl
43with a NULL parameter for
44.Fa old ;
45the size of the value will be returned in the location pointed to by
46.Fa oldlenp .
47If the old value is not desired,
48.Fa old
49and
50.Fa oldlenp
51can be set to NULL.
52.Pp
53To set a new value,
54.Fa new
55is set to point to a buffer of length
56.Fa newlen
57from which the requested value is to be taken.
58If the setting of a new value is not desired,
59.Fa new
60should be set to NULL and
61.Fa newlen
62set to 0.
63.Pp
64For example, to retrieve the maximum number of processes allowed
65in the system, one would use the follow request:
66.sp
67.Bd -literal -offset indent -compact
68int name[2], len, maxproc;
69
70name[0] = CTL_KERN;
71name[1] = KERN_MAXPROC;
72len = sizeof maxproc;
73sysctl(name, 2, &maxproc, &len, NULL, 0);
74.Ed
75.Sh RETURN VALUES
76If the call to
77.Fn sysctl
78is successful, the length of the old value is returned.
79Otherwise \-1 is returned and
80.Va errno
81is set appropriately.
82.Sh ERRORS
83The following error may be reported:
84.Bl -tag -width Er
85.It Bq Er EFAULT
86The buffer
87.Fa name ,
88.Fa old ,
89.Fa new ,
90or length pointer
91.Fa oldlenp
92contains an invalid address.
93.It Bq Er EINVAL
94The
95.Fa name
96array is less than two or greater than CTL_MAXNAME.
97.It Bq Er EINVAL
98A non-null
99.Fa new
100is given and its specified length in
101.Fa newlen
102is too large or too small.
103.It Bq Er ENOMEM
104The length pointed to by
105.Fa oldlenp
106is too short to hold the requested value.
107.It Bq Er ENOTDIR
108The
109.Fa name
110array specifies an intermediate rather than terminal name.
111.It Bq Er EOPNOTSUPP
112The
113.Fa name
114array specifies a value that is unknown.
115.It Bq Er EPERM
116An attempt is made to set a read-only value.
117.It Bq Er EPERM
118A process without appropriate privilege attempts to set a value.
119.El
120.Sh FILES
121.Bl -tag -width <vm/vm_param.h> -compact
122.It Pa <sys/sysctl.h>
123definitions for top level identifiers and second level kernel
124and hardware identifiers
125.It Pa <sys/socket.h>
126definitions for second level network identifiers
127.It Pa <vm/vm_param.h>
128definitions for second level virtual memory identifiers
129.El
130.Sh SEE ALSO
131.Xr sysctl 8
132.Sh HISTORY
133.Fn sysctl
134first appeared in 4.4BSD.
135