Scroll to navigation

SYSCTL(2) Manual do Programador do Linux SYSCTL(2)

NOME

sysctl - lê/escreve parâmetros do sistema

SINOPSE

#include <unistd.h>
#include <linux/sysctl.h>
int _sysctl(struct __sysctl_args *args);

Note: There is no glibc wrapper for this system call; see NOTES.

DESCRIÇÃO

Do not use this system call! See NOTES.

A chamada _sysctl() lê e/ou escrever parâmetros do kernel. Por exemplo, o nome da máquina, ou o número máximo de arquivos abertos. O argumento tem a forma


struct __sysctl_args {

int *name; /* integer vector describing variable */
int nlen; /* length of this vector */
void *oldval; /* 0 or address where to store old value */
size_t *oldlenp; /* available room for old value,
overwritten by actual size of old value */
void *newval; /* 0 or address of new value */
size_t newlen; /* size of new value */ };

Esta chamada faz um busca numa árvore de estrutura, possivelmente parecida com uma árvore de diretório sob /proc/sys, e se o item requisitado é encontrado é chamada alguma rotina apropriada para ler ou modificar o valor.

VALOR DE RETORNO

Em caso de sucesso _sysctl() devolve 0. Caso contráio, -1 é devolvido e errno é selecionado adequadamente.

ERROS

No search permission for one of the encountered "directories", or no read permission where oldval was nonzero, or no write permission where newval was nonzero.
O pedido perguntou pelo valor anterior selecionando oldval como não nulo, mas permitido zero espaço em oldlenp.
name não foi encontrado.

DE ACORDO COM

This call is Linux-specific, and should not be used in programs intended to be portable. A sysctl() call has been present in Linux since version 1.3.57. It originated in 4.4BSD. Only Linux has the /proc/sys mirror, and the object naming schemes differ between Linux and 4.4BSD, but the declaration of the sysctl() function is the same in both.

NOTAS

Glibc does not provide a wrapper for this system call; call it using syscall(2). Or rather... don't call it: use of this system call has long been discouraged, and it is so unloved that it is likely to disappear in a future kernel version. Since Linux 2.6.24, uses of this system call result in warnings in the kernel log. Remove it from your programs now; use the /proc/sys interface instead.

This system call is available only if the kernel was configured with the CONFIG_SYSCTL_SYSCALL option.

BUGS

The object names vary between kernel versions, making this system call worthless for applications.

Nem todos objetos disponíveis são documentados adequadamente.

Ainda não é possível mudar sistema operacional escrevendo /proc/sys/kernel/ostype.

EXEMPLO

#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <linux/sysctl.h>
int _sysctl(struct __sysctl_args *args );
#define OSNAMESZ 100
int
main(void)
{

struct __sysctl_args args;
char osname[OSNAMESZ];
size_t osnamelth;
int name[] = { CTL_KERN, KERN_OSTYPE };
memset(&args, 0, sizeof(struct __sysctl_args));
args.name = name;
args.nlen = sizeof(name)/sizeof(name[0]);
args.oldval = osname;
args.oldlenp = &osnamelth;
osnamelth = sizeof(osname);
if (syscall(SYS__sysctl, &args) == -1) {
perror("_sysctl");
exit(EXIT_FAILURE);
}
printf("This machine is running %*s\n", osnamelth, osname);
exit(EXIT_SUCCESS); }

VEJA TAMBÉM

proc(5)

COLOFÃO

Esta página faz parte da versão 4.16 do projeto Linux man-pages. Uma descrição do projeto, informações sobre relatórios de bugs e a versão mais recente desta página podem ser encontradas em https://www.kernel.org/doc/man-pages/.

TRADUÇÃO

A tradução para português brasileiro desta página man foi criada por André Luiz Fassone <lonely_wolf@ig.com.br> e Marcelo Pereira da Silva <marcelo@pereira.com>

Esta tradução é uma documentação livre; leia a Licença Pública Geral GNU Versão 3 ou posterior para as condições de direitos autorais. Nenhuma responsabilidade é aceita.

Se você encontrar algum erro na tradução desta página de manual, envie um e-mail para a lista de discussão de tradutores.

15 setembro 2017 Linux