Linux sysconf函数 -- get configurable system variables

sysconf函数用于获取Linux系统的可配置系统限制或选项变量的当前值。它定义在POSIX.1标准中,通过<unistd.h>头文件中的符号常量指定查询的系统变量。当调用不成功时,返回-1并设置errno;如果变量关联的功能不受支持,也会返回-1,但errno不修改。成功则返回变量的当前值。
部署运行你感兴趣的模型镜像
  • 函数原型

    long sysconf(int name);
    
  • 头文件

    #include <unistd.h>
    
  • 描述

    get configurable system variables.

    This interface is defined by IEEE Std 1003.1-1988 (``POSIX.1’’). A far more complete interface is available using sysctl(3).

    The sysconf() function provides a method for applications to determine the current value of a configurable system limit or option variable. The name argument specifies the system variable to be queried. Symbolic constants for each name value are found in the include file <unistd.h>. Shell programmers who need access to these parameters should use the getconf(1) utility.

    主要是来获取系统变量的。

  • 参数

    	_SC_ARG_MAX
                 The maximum bytes of argument to execve(2).
    
         _SC_CHILD_MAX
                 The maximum number of simultaneous processes per user id.
    
         _SC_CLK_TCK
                 The frequency of the statistics clock in ticks per second.
    
         _SC_IOV_MAX
                 The maximum number of elements in the I/O vector used by readv(2), writev(2), recvmsg(2), and
                 sendmsg(2).
    
         _SC_NGROUPS_MAX
                 The maximum number of supplemental groups.
    
         _SC_NPROCESSORS_CONF
                 The number of processors configured.
    
         _SC_NPROCESSORS_ONLN
                 The number of processors currently online.
    
         _SC_OPEN_MAX
                 The maximum number of open files per user id.
    
         _SC_PAGESIZE
                 The size of a system page in bytes.
    
         _SC_STREAM_MAX
                 The minimum maximum number of streams that a process may have open at any one time.
    
         _SC_TZNAME_MAX
                 The minimum maximum number of types supported for the name of a timezone.
    
         _SC_JOB_CONTROL
                 Return 1 if job control is available on this system, otherwise -1.
    
         _SC_SAVED_IDS
                 Returns 1 if saved set-group and saved set-user ID is available, otherwise -1.
    
         _SC_VERSION
                 The version of IEEE Std 1003.1 (POSIX.1) with which the system attempts to comply.
    
         _SC_BC_BASE_MAX
                 The maximum ibase/obase values in the bc(1) utility.
    
         _SC_BC_DIM_MAX
                 The maximum array size in the bc(1) utility.
    
         _SC_BC_SCALE_MAX
                 The maximum scale value in the bc(1) utility.
    
         _SC_BC_STRING_MAX
                 The maximum string length in the bc(1) utility.
    
         _SC_COLL_WEIGHTS_MAX
                 The maximum number of weights that can be assigned to any entry of the LC_COLLATE order keyword in the
                 locale definition file.
    
         _SC_EXPR_NEST_MAX
                 The maximum number of expressions that can be nested within parenthesis by the expr(1) utility.
    
         _SC_LINE_MAX
                 The maximum length in bytes of a text-processing utility's input line.
    
    	_SC_RE_DUP_MAX
    	             The maximum number of repeated occurrences of a regular expression permitted when using interval nota-
    	             tion.
    
         _SC_2_VERSION
                 The version of IEEE Std 1003.2 (POSIX.2) with which the system attempts to comply.
    
         _SC_2_C_BIND
                 Return 1 if the system s C-language development facilities support the C-Language Bindings Option, oth-
                 erwise -1.
    
         _SC_2_C_DEV
                 Return 1 if the system supports the C-Language Development Utilities Option, otherwise -1.
    
         _SC_2_CHAR_TERM
                 Return 1 if the system supports at least one terminal type capable of all operations described in IEEE
                 Std 1003.2 (POSIX.2), otherwise -1.
    
         _SC_2_FORT_DEV
                 Return 1 if the system supports the FORTRAN Development Utilities Option, otherwise -1.
    
         _SC_2_FORT_RUN
                 Return 1 if the system supports the FORTRAN Runtime Utilities Option, otherwise -1.
    
         _SC_2_LOCALEDEF
                 Return 1 if the system supports the creation of locales, otherwise -1.
    
         _SC_2_SW_DEV
                 Return 1 if the system supports the Software Development Utilities Option, otherwise -1.
    
         _SC_2_UPE
                 Return 1 if the system supports the User Portability Utilities Option, otherwise -1.
    
  • 返回值

    If the call to sysconf() is not successful, -1 is returned and errno is set appropriately. Otherwise, if the variable is associated with functionality that is not supported, -1 is returned and errno is not modified. Otherwise, the current variable value is returned.

  • 举个例子

    #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 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;
    }
    

    输出结果为:

    The number of processors configured is :4
    The number of processors currently online (available) is :4
    The pagesize: 4096
    The number of pages: 2097152
    The memory size: 8192 MB
    The number of files max opened:: 256
    The number of ticks per second: 100
    The max length of host name: 255
    The max number of simultaneous processes per user: 709
    

您可能感兴趣的与本文相关的镜像

TensorFlow-v2.9

TensorFlow-v2.9

TensorFlow

TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值