Scroll to navigation

sysctl(2) System Calls Manual sysctl(2)

이름

sysctl - 시스템 파라미터들을 읽고 쓴다.

요약

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

설명

This system call no longer exists on current kernels! See NOTES.

_sysctl() 시스템 콜은 커널 파리미터들을 읽고 쓴다. 예를 들어, 호스트 이름이나 열린 파일들의 최대 수 등이다. 인자는 다음과 같은 형태이다:


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 */ };

이 함수는 트리 구조에서 탐색을 하며 /proc/sys아래의 디렉토리 트리와 비슷하다. 그리고 만일 요구된 아이템이 발견된다면 몇몇 적당한 루틴들이 이 값을 읽거나 번경하기 위해서 호출된다.

반환값

성공시, _sysctl() 는 0이 리턴되다. 그렇지 않으면, -1 값이 리턴되며 errno 는 에러를 가리키며 설정된다.

에러

만난 `directories'중 하나에 대한 탐색 허가권이 없거나, oldval 가 0이 아닌곳의 읽기 허가권이 없거나, newval 이 0이 아닌곳의 쓰기 허가권이 없다.
호출은 non-NULL인 oldval 를 설정하여 전 값을 요구했지만, oldlenp에 있는 곳은 0 을 허가한다.
name 이 발견되지 않았다.

버전S

This system call first appeared in Linux 1.3.57. It was removed in Linux 5.5; glibc support was removed in glibc 2.32.

표준

This call is Linux-specific, and should not be used in programs intended to be portable. 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.

주의

Use of this system call was long discouraged: since Linux 2.6.24, uses of this system call result in warnings in the kernel log, and in Linux 5.5, the system call was finally removed. Use the /proc/sys interface instead.

Note that on older kernels where this system call still exists, it is available only if the kernel was configured with the CONFIG_SYSCTL_SYSCALL option. Furthermore, glibc does not provide a wrapper for this system call, necessitating the use of syscall(2).

버그

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

이용할수 있는 모든 객체들이 문서화 되어 있지는 않다.

아직은 /proc/sys/kernel/ostype에 쓰기를 하여 OS를 변경하는것은 가능하지 않다.

폐제

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

int name[] = { CTL_KERN, KERN_OSTYPE };
char osname[OSNAMESZ];
size_t osnamelth;
struct __sysctl_args args;
memset(&args, 0, sizeof(args));
args.name = name;
args.nlen = ARRAY_SIZE(name);
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", (int) osnamelth, osname);
exit(EXIT_SUCCESS); }

추가 참조

proc(5)

번역

이 매뉴얼 페이지의 한국어 번역은 다음에 의해 편집되었습니다: 정강훈 <skyeyes@soback.kornet.net>

이 번역은 무료 문서입니다. 저작권 조건에 대해서는 GNU General Public License 버전 3 이상을 읽으십시오. 책임이 없습니다.

이 매뉴얼 페이지의 번역에서 오류를 발견하면 translation-team-ko@googlegroups.com 로 이메일을 보내주십시오.

2022년 12월 4일 Linux man-pages 6.03