一、与文件或目录无关的运行时限制(sysconf函数)
sysconf 函数用来获取系统执行的配置信息。例如页大小、最大页数、cpu个数、打开句柄的最大个数等等。
函数原型:
#include <unistd.h>
long sysconf(int name);
以下为常用的name参数:
_SC_CHILD_MAX:每个user可同时运行的最大进程数
_SC_HOST_NAME_MAX:hostname最大长度,需小于_POSIX_HOST_NAME_MAX (255)
_SC_OPEN_MAX:一个进程可同时打开的文件最大数
_SC_PAGESIZE:一个page的大小,单位byte
_SC_PHYS_PAGES:物理内存总page数
_SC_AVPHYS_PAGES:当前可获得的物理内存page数
_SC_NPROCESSORS_CONF:配置的处理器个数
_SC_NPROCESSORS_ONLN:当前可获得的处理器个数
_SC_CLK_TCK:每秒对应的时钟tick数
实例程序:
#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 number of simultaneous processes per user: %ld\n", sysconf(_SC_CHILD_MAX));
return 0;
}
我的电脑的配置
root@VM-4-15-ubuntu:/home/ubuntu/zsy/sipp/sipp-3.6.1# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel(R) Xeon(R) Gold 6133 CPU @ 2.50GHz
stepping : 3
microcode : 0x1
cpu MHz : 2494.134
cache size : 28160 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 arat
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit srbds
bogomips : 4988.26
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel(R) Xeon(R) Gold 6133 CPU @ 2.50GHz
stepping : 3
microcode : 0x1
cpu MHz : 2494.134
cache size : 28160 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
apicid : 1
initial apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 arat
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit srbds
bogomips : 4988.26
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
运行结果如下
root@VM-4-15-ubuntu:/home/ubuntu/zsy/sipp/sipp-3.6.1# ./sysconf
The number of processors configured is :2
The number of processors currently online (available) is :2
The pagesize: 4096
The number of pages: 507535
The number of available pages: 57964
The memory size: 1982 MB
The number of files max opened:: 1024
The number of ticks per second: 100
The max length of host name: 64
The max number of simultaneous processes per user: 7549
二、与文件或目录有关的运行时限制(pathconf和fpathconf)
函数原型:
long int pathconf(const char *pathname,int parameter);
long int fpathconf(int filedes,int parameter);