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