HP_Socket学习01 Linux

#、##、__VA_ARGS__和##__VA_ARGS__的作用

https://blog.csdn.net/q2519008/article/details/80934815
##__VA_ARGS__ 宏前面加上##的作用在于,当可变参数的个数为0时,这里的##起到把前面多余的","去掉的作用,否则会编译出错

sysconf

获得系统配置信息
DESCRIPTION
       POSIX  allows  an application to test at compile or run time whether certain options are supported, or what the value is of certain
       configurable constants or limits.

       At compile time this is done by including <unistd.h> and/or <limits.h> and testing the value of certain macros.

       At run time, one can ask for numerical values using the present function sysconf().  One can ask  for  numerical  values  that  may
       depend  on  the  filesystem  in which a file resides using fpathconf(3) and pathconf(3).  One can ask for string values using conf‐
       str(3).

       The values obtained from these functions are system configuration constants.  They do not change during the lifetime of a process.

       For options, typically, there is a constant _POSIX_FOO that may be defined in <unistd.h>.  If it is undefined, one  should  ask  at
       run  time.   If  it is defined to -1, then the option is not supported.  If it is defined to 0, then relevant functions and headers
       exist, but one has to ask at run time what degree of support is available.  If it is defined to a value other than -1  or  0,  then
       the  option  is  supported.   Usually the value (such as 200112L) indicates the year and month of the POSIX revision describing the
       option.  Glibc uses the value 1 to indicate support as long as the POSIX revision has not been published yet.  The sysconf()  argu‐
       ment will be _SC_FOO.  For a list of options, see posixoptions(7).

       For  variables  or  limits,  typically,  there  is  a  constant  _FOO, maybe defined in <limits.h>, or _POSIX_FOO, maybe defined in
       <unistd.h>.  The constant will not be defined if the limit is unspecified.  If the constant  is  defined,  it  gives  a  guaranteed
       value,  and  a  greater  value  might  actually be supported.  If an application wants to take advantage of values which may change
       between systems, a call to sysconf() can be made.  The sysconf() argument will be _SC_FOO.
翻译:
描述

POSIX允许应用程序在编译或运行时测试是否支持某些选项,或者哪些值是确定的。可配置常量或限制。
在编译时,这是通过包括<unistd.h>和/或<limits.h>并测试某些宏的值来完成的。
在运行时,可以使用当前函数sysconf()请求数值。我们可以要求数值取决于使用fpathconf(3)和pathconf(3)存放文件的文件系统。可以使用conf‐请求字符串值STR(3)。
从这些函数中获得的值是系统配置常数。它们在进程的生命周期中不会改变。
对于选项,通常有一个常量posix foo可以在<unistd.h>中定义。如果未定义,应在运行时间。如果定义为-1,则不支持该选项。如果定义为0,则相关函数和头存在,但必须在运行时询问可用的支持程度。如果定义的值不是-1或0,则支持该选项。通常,值(例如200112L)表示描述选择权。glibc使用值1表示支持,只要posix版本尚未发布。sysconf()参数
我们将为您提供服务。有关选项列表,请参见posixOptions(7)。
对于变量或限制,通常有一个常量foo,可以在<limits.h>中定义,也可以在
< UNITST.H>如果未指定限制,则不会定义常量。如果定义了常量,它将给出一个有保证的值,实际上可能支持更大的值。如果应用程序希望利用可能发生更改的值在系统之间,可以调用sysconf()。sysconf()参数将是_sc_foo。
参数看man page
RETURN VALUE
       The return value of sysconf() is one of the following:

       *  On  error,  -1 is returned and errno is set to indicate the cause of
          the error (for example, EINVAL, indicating that name is invalid).

       *  If name corresponds to a maximum or minimum limit, and that limit is
          indeterminate, -1 is returned and errno is not changed.  (To distin‐
          guish an indeterminate limit from an error, set errno to zero before
          the  call,  and  then  check  whether  errno  is  nonzero when -1 is
          returned.)

       *  If name corresponds to an option, a positive value  is  returned  if
          the  option  is  supported,  and -1 is returned if the option is not
          supported.

       *  Otherwise, the current value of the option  or  limit  is  returned.
          This value will not be more restrictive than the corresponding value
          that was described to the application in  <unistd.h>  or  <limits.h>
          when the application was compiled.

ERRORS
       EINVAL name is invalid.

sysconf(_SC_NPROCESSORS_ONLN)

_SC_NPROCESSORS_CONF
              The    number    of    processors    configured.     See    also
              get_nprocs_conf(3).
获得处理器的数量

sysinfo

sysinfo()返回有关内存和交换使用情况以及平均负载的某些统计信息。
RETURN VALUE
       On success, sysinfo() returns zero.  On error, -1 is returned, and errno is set to indicate the cause of the error.

ERRORS
       EFAULT info is not a valid address.

VERSIONS
       sysinfo() first appeared in Linux 0.98.pl6.

CONFORMING TO
       This function is Linux-specific, and should not be used in programs intended to be portable.

NOTES
       All of the information provided by this system call is also available via /proc/meminfo and /proc/loadavg.

getnprocs

getpagesize

getpid

syscall(__NR_gettid)

pthread_self

pthread_equal

inline void __asm_nop() {__asm__  __volatile__("nop" : : : "memory");}

inline void __asm_rep_nop() {__asm__ __volatile__("rep; nop" : : : "memory");}

#if defined(__i386__) || defined(__x86_64)

inline void __asm_pause() {__asm__ __volatile__("pause;");}

#elif defined(__arm64)

inline void __asm_pause() {__asm__ __volatile__("yield" : : : "memory");}

#else

inline void __asm_pause() {__asm_nop();}

#endif

sched_yield

猜你喜欢

转载自blog.csdn.net/sinat_36391009/article/details/85722004