zoukankan      html  css  js  c++  java
  • 系统调用—sysconf

    代码:

     static inline unsigned int getCoresNum(void)
    {
        return sysconf(_SC_NPROCESSORS_ONLN);
    }

    The use of threads or processes with shared memory allows an application to take advantage of all the processing power a system can provide. If the task can be parallelized the optimal way to write an application is to have at any time as many processes running as there are processors. To determine the number of processors available to the system one can run

      sysconf (_SC_NPROCESSORS_CONF)
    

    which returns the number of processors the operating system configured. But it might be possible for the operating system to disable individual processors and so the call

      sysconf (_SC_NPROCESSORS_ONLN
    

    returns the number of processors which are currently online (i.e., available).

    或者直接调用linux提供的函数:

    Function: int get_nprocs_conf (void)

    Preliminary: | MT-Safe | AS-Unsafe heap lock | AC-Unsafe lock fd mem | See POSIX Safety Concepts.

    The get_nprocs_conf function returns the number of processors the operating system configured.

    This function is a GNU extension.

    Function: int get_nprocs (void)

    Preliminary: | MT-Safe | AS-Safe | AC-Safe fd | See POSIX Safety Concepts.

    The get_nprocs function returns the number of available processors.

    This function is a GNU extension.

    Before starting more threads it should be checked whether the processors are not already overused. Unix systems calculate something called the load average. This is a number indicating how many processes were running. This number is an average over different periods of time (normally 1, 5, and 15 minutes).

    Function: int getloadavg (double loadavg[], int nelem)

    Preliminary: | MT-Safe | AS-Safe | AC-Safe fd | See POSIX Safety Concepts.

    This function gets the 1, 5 and 15 minute load averages of the system. The values are placed in loadavggetloadavg will place at most nelem elements into the array but never more than three elements. The return value is the number of elements written to loadavg, or -1 on error.

    This function is declared in stdlib.h.

  • 相关阅读:
    mssql索引视图无法对视图创建 索引,因为该视图未绑定到架构
    说说回车键触发表单提交的问题
    在C#中使用SqlDbType.Xml类型参数
    使用nginx实施负载均衡
    SQL Server 索引中include的魅力(具有包含性列的索引)
    群发“站内信”的实现
    ORM映射框架总结终极JSON
    51 地图基本接口(二)
    通用短信平台接口
    ORM映射框架总结Flash 处理
  • 原文地址:https://www.cnblogs.com/rex-2018-cloud/p/10418945.html
Copyright © 2011-2022 走看看