标签:
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; }
标签:
原文地址:http://www.cnblogs.com/how-are-you/p/5629425.html