Node:System Parameters, Previous:Filesystem Handling, Up:System Management
This section describes the sysctl
function, which gets and sets
a variety of system parameters.
The symbols used in this section are declared in the file sysctl.h
.
int sysctl (int *names, int nlen, void *oldval, | Function |
size_t *oldlenp, void *newval, size_t newlen)
The set of available parameters depends on the kernel configuration and can change while the system is running, particularly when you load and unload loadable kernel modules. The system parameters with which For example, the first component of the path for all the paging
parameters is the value The format of the value of a parameter depends on the parameter. Sometimes it is an integer; sometimes it is an ASCII string; sometimes it is an elaborate structure. In the case of the free page thresholds used in the example above, the parameter value is a structure containing several integers. In any case, you identify a place to return the parameter's value with oldval and specify the amount of storage available at that location as *oldlenp. *oldlenp does double duty because it is also the output location that contains the actual length of the returned value. If you don't want the parameter value returned, specify a null pointer for oldval. To set the parameter, specify the address and length of the new value as newval and newlen. If you don't want to set the parameter, specify a null pointer as newval. If you get and set a parameter in the same Each system parameter has a set of permissions similar to the permissions for a file (including the permissions on directories in its path) that determine whether you may get or set it. For the purposes of these permissions, every parameter is considered to be owned by the superuser and Group 0 so processes with that effective uid or gid may have more access to system parameters. Unlike with files, the superuser does not invariably have full permission to all system parameters, because some of them are designed not to be changed ever.
|
If you have a Linux kernel with the proc
filesystem, you can get
and set most of the same parameters by reading and writing to files in
the sys
directory of the proc
filesystem. In the sys
directory, the directory structure represents the hierarchical structure
of the parameters. E.g. you can display the free page thresholds with
cat /proc/sys/vm/freepages
Some more traditional and more widely available, though less general, GNU C library functions for getting and setting some of the same system parameters are:
getdomainname
, setdomainname
gethostname
, sethostname
(See Host Identification.)
uname
(See Platform Type.)
bdflush