?? sysctl.3
字號:
.\" Copyright (c) 1993.\" The Regents of the University of California. All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)sysctl.3 8.1 (Berkeley) 6/4/93.\".Dd "June 4, 1993".Dt SYSCTL 3.Os.Sh NAME.Nm sysctl.Nd get or set system information.Sh SYNOPSIS.Fd #include <sys/sysctl.h>.Ft int.Fn sysctl "int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "void *newp" "size_t newlen".Sh DESCRIPTIONThe.Nm sysctlfunction retrieves system information and allows processes withappropriate privileges to set system information.The information available from.Nm sysctlconsists of integers, strings, and tables.Information may be retrieved and set from the command interfaceusing the .Xr sysctl 1utility..PpUnless explicitly noted below,.Nm sysctlreturns a consistent snapshot of the data requested.Consistency is obtained by locking the destinationbuffer into memory so that the data may be copied out without blocking.Calls to.Nm sysctlare serialized to avoid deadlock..PpThe state is described using a ``Management Information Base'' (MIB)style name, listed in.Fa name ,which is a.Fa namelenlength array of integers..PpThe information is copied into the buffer specified by.Fa oldp .The size of the buffer is given by the location specified by.Fa oldlenpbefore the call,and that location gives the amount of data copied after a successful call.If the amount of data available is greaterthan the size of the buffer supplied,the call supplies as much data as fits in the buffer providedand returns with the error code ENOMEM.If the old value is not desired,.Fa oldpand.Fa oldlenpshould be set to NULL..PpThe size of the available data can be determined by calling .Nm sysctlwith a NULL parameter for.Fa oldp .The size of the available data will be returned in the location pointed to by.Fa oldlenp .For some operations, the amount of space may change often.For these operations,the system attempts to round up so that the returned size islarge enough for a call to return the data shortly thereafter..PpTo set a new value,.Fa newpis set to point to a buffer of length.Fa newlenfrom which the requested value is to be taken.If a new value is not to be set,.Fa newpshould be set to NULL and.Fa newlenset to 0..PpThe top level names are defined with a CTL_ prefix in.Pa <sys/sysctl.h> ,and are as follows.The next and subsequent levels down are found in the include fileslisted here, and described in separate sections below..Pp.Bl -column CTLXMACHDEPXXX "Next level namesXXXXXX" -offset indent.It Sy Pa Name Next level names Description.It CTL\_DEBUG sys/sysctl.h Debugging.It CTL\_FS sys/sysctl.h File system.It CTL\_HW sys/sysctl.h Generic CPU, I/O.It CTL\_KERN sys/sysctl.h High kernel limits.It CTL\_MACHDEP sys/sysctl.h Machine dependent.It CTL\_NET sys/socket.h Networking.It CTL\_USER sys/sysctl.h User-level.It CTL\_VM vm/vm_param.h Virtual memory.El.PpFor example, the following retrieves the maximum number of processes allowedin the system:.Bd -literal -offset indent -compactint mib[2], maxproc;size_t len;.spmib[0] = CTL_KERN;mib[1] = KERN_MAXPROC;len = sizeof(maxproc);sysctl(mib, 2, &maxproc, &len, NULL, 0);.Ed.spTo retrieve the standard search path for the system utilities:.Bd -literal -offset indent -compactint mib[2];size_t len;char *p;.spmib[0] = CTL_USER;mib[1] = USER_CS_PATH;sysctl(mib, 2, NULL, &len, NULL, 0);p = malloc(len);sysctl(mib, 2, p, &len, NULL, 0);.Ed.Sh CTL_DEBUGThe debugging variables vary from system to system.A debugging variable may be added or deleted without need to recompile.Nm sysctlto know about it.Each time it runs,.Nm sysctlgets the list of debugging variables from the kernel anddisplays their current values.The system defines twenty .Ns ( Va struct ctldebug )variables named .Nm debug0through.Nm debug19 .They are declared as separate variables so that they can beindividually initialized at the location of their associated variable.The loader prevents multiple use of the same variable by issuing errorsif a variable is initialized in more than one place.For example, to export the variable.Nm dospecialcheckas a debugging variable, the following declaration would be used:.Bd -literal -offset indent -compactint dospecialcheck = 1;struct ctldebug debug5 = { "dospecialcheck", &dospecialcheck };.Ed.Sh CTL_FSThere are currently no second level names for the file system..Sh CTL_HWThe string and integer information available for the CTL_HW levelis detailed below.The changeable column shows whether a process with appropriateprivilege may change the value..Bl -column "Second level nameXXXXXX" integerXXX -offset indent.It Sy Pa Second level name Type Changeable.It HW\_MACHINE string no.It HW\_MODEL string no.It HW\_NCPU integer no.It HW\_BYTEORDER integer no.It HW\_PHYSMEM integer no.It HW\_USERMEM integer no.It HW\_PAGESIZE integer no.\".It HW\_DISKNAMES integer no.\".It HW\_DISKSTATS integer no.El.Pp.Bl -tag -width "123456".It Li HW_MACHINEThe machine class..It Li HW_MODELThe machine model.It Li HW_NCPUThe number of cpus..It Li HW_BYTEORDERThe byteorder (4,321, or 1,234)..It Li HW_PHYSMEMThe bytes of physical memory..It Li HW_USERMEMThe bytes of non-kernel memory..It Li HW_PAGESIZEThe software page size..\".It Fa HW_DISKNAMES.\".It Fa HW_DISKSTATS.El.Sh CTL_KERNThe string and integer information available for the CTL_KERN levelis detailed below.The changeable column shows whether a process with appropriateprivilege may change the value.The types of data currently available are process information,system vnodes, the open file entries, routing table entries,virtual memory statistics, load average history, and clock rateinformation..Bl -column "KERNXCHOWNXRESTRICTEDXXX" "struct clockrateXXX" -offset indent.It Sy Pa Second level name Type Changeable.It KERN\_ARGMAX integer no.It KERN\_BOOTTIME struct timeval no.It KERN\_CHOWN\_RESTRICTED integer no.It KERN\_CLOCKRATE struct clockinfo no.It KERN\_FILE struct file no.It KERN\_HOSTID integer yes.It KERN\_HOSTNAME string yes.It KERN\_JOB\_CONTROL integer no.It KERN\_LINK\_MAX integer no.It KERN\_MAXFILES integer yes.It KERN\_MAXPROC integer yes.It KERN\_MAXVNODES integer yes.It KERN\_MAX\_CANON integer no.It KERN\_MAX\_INPUT integer no.It KERN\_NAME\_MAX integer no.It KERN\_NGROUPS integer no.It KERN\_NO\_TRUNC integer no.It KERN\_OSRELEASE string no.It KERN\_OSREV integer no.It KERN\_OSTYPE string no.It KERN\_PATH\_MAX integer no.It KERN\_PIPE\_BUF integer no.It KERN\_POSIX1 integer no.It KERN\_PROC struct proc no.It KERN\_PROF node not applicable.It KERN\_SAVED\_IDS integer no.It KERN\_SECURELVL integer raise only.It KERN\_VDISABLE integer no.It KERN\_VERSION string no.It KERN\_VNODE struct vnode no.El.Pp.Bl -tag -width "123456".It Li KERN_ARGMAXThe maximum bytes of argument to.Xr exec 2 ..It Li KERN_BOOTTIMEA.Va struct timevalstructure is returned.This structure contains the time that the system was booted..It Li KERN_CHOWN_RESTRICTEDReturn 1 if appropriate privileges are required for the.Xr chown 2system call, otherwise 0..It Li KERN_CLOCKRATEA.Va struct clockinfostructure is returned.This structure contains the clock, statistics clock and profiling clockfrequencies, and the number of micro-seconds per hz tick..It Li KERN_FILEReturn the entire file table.The returned data consists of a single.Va struct fileheadfollowed by an array of.Va struct file ,whose size depends on the current number of such objects in the system..It Li KERN_HOSTIDGet or set the host id..It Li KERN_HOSTNAMEGet or set the hostname..It Li KERN_JOB_CONTROLReturn 1 if job control is available on this system, otherwise 0..It Li KERN_LINK_MAXThe maximum file link count..It Li KERN_MAXFILESThe maximum number of open files that may be open in the system..It Li KERN_MAXPROCThe maximum number of simultaneous processes the system will allow..It Li KERN_MAXVNODESThe maximum number of vnodes available on the system..It Li KERN_MAX_CANONThe maximum number of bytes in terminal canonical input line..It Li KERN_MAX_INPUTThe minimum maximum number of bytes for which space is available ina terminal input queue..It Li KERN_NAME_MAXThe maximum number of bytes in a file name..It Li KERN_NGROUPSThe maximum number of supplemental groups..It Li KERN_NO_TRUNCReturn 1 if file names longer than KERN_NAME_MAX are truncated..It Li KERN_OSRELEASEThe system release string..It Li KERN_OSREVThe system revision string..It Li KERN_OSTYPEThe system type string..It Li KERN_PATH_MAXThe maximum number of bytes in a pathname..It Li KERN_PIPE_BUFThe maximum number of bytes which will be written atomically to a pipe..It Li KERN_POSIX1The version of ISO/IEC 9945 (POSIX 1003.1) with which the systemattempts to comply..It Li KERN_PROCReturn the entire process table, or a subset of it.An array of
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -