Linux函数整理 sysconf
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux函数整理 sysconf相关的知识,希望对你有一定的参考价值。
sysconf这个函数用来获取系统执行的配置信息。例如页大小、最大页数、cpu个数、打开句柄的最大个数等。
#include <stdio.h> #include <unistd.h> #define ONE_MB (1024 * 1024) int main() {
//处理器数目 printf("The number of processors configured is :%ld\n", sysconf(_SC_NPROCESSORS_CONF)); printf("The number of processors currently online (available) is :%ld\n", sysconf(_SC_NPROCESSORS_ONLN));
//页大小 printf ("The pagesize: %ld\n", sysconf(_SC_PAGESIZE));
//页数目 printf ("The number of pages: %ld\n", sysconf(_SC_PHYS_PAGES)); printf ("The number of available pages: %ld\n", sysconf(_SC_AVPHYS_PAGES));
//内存 printf ("The memory size: %lld MB\n", (long long)sysconf(_SC_PAGESIZE) * (long long)sysconf(_SC_PHYS_PAGES) / ONE_MB );
//最大打开文件数 printf ("The number of files max opened:: %ld\n", sysconf(_SC_OPEN_MAX));
//时钟 printf("The number of ticks per second: %ld\n", sysconf(_SC_CLK_TCK)); printf ("The max length of host name: %ld\n", sysconf(_SC_HOST_NAME_MAX)); printf ("The max length of login name: %ld\n", sysconf(_SC_LOGIN_NAME_MAX)); return 0; }
以上是关于Linux函数整理 sysconf的主要内容,如果未能解决你的问题,请参考以下文章