print OS 软限制和硬限制的值

来源:互联网 发布:山西网络教育 编辑:程序博客网 时间:2024/06/06 16:59

一源代码

    1  #include "apue.h"
     2  #include <sys/resource.h>
     3
     4  #define doit(name) pr_limits(#name, name)
     5
     6  static void pr_limits(char *, int);
     7
     8  int main(void)
     9  {
    10  #ifdef RLIMIT_AS
    11          doit(RLIMIT_AS);
    12  #endif
    13
    14          doit(RLIMIT_CORE);
    15          doit(RLIMIT_CPU);
    16          doit(RLIMIT_DATA);
    17          doit(RLIMIT_FSIZE);
    18  #ifdef RLIMIT_MEMLOCK
    19          doit(RLIMIT_MEMLOCK);
    20  #endif
    21
    22  #ifdef RLIMIT_MSGQUEUE
    23          doit(RLIMIT_MSGQUEUE);
    24  #endif
    25
    26  #ifdef RLIMIT_RICE
    27          doit(RLIMIT_RICE);
    28  #endif
    29
    30          doit(RLIMIT_NOFILE);
    31
    32  #ifdef RLIMIT_NPTS
    33          doit(RLIMIT_NPRS);
    34  #endif
    35
    36  #ifdef RLIMIT_RSS
    37          doit(RLIMIT_RSS);
    38  #endif
    39
    40  #ifdef RLIMIT_SBSSIZE
    41          doit(RLIMT_SBSSIZE);
    42  #endif
    43
    44  #ifdef RLIMIT_SIGPENDING
    45          doit(RLIMIT_SIGPENDING);
    46  #endif
    47
    48          doit(RLIMIT_STACK);
    49
    50  #ifdef RLIMIT_VMEM
    51          doit(RLIMIT_VMEM);
    52  #endif
    53
    54  exit (0);
    55  }
    56
    57
    58  static void
    59  pr_limits(char *name, int resource)
    60  {
    61          struct rlimit limit;
    62          unsigned long long lim;
    63
    64          if (getrlimit(resource,&limit) < 0)
    65                  err_sys("getrlimit error for %s",name);
    66          printf("%-14s ",name);
    67          if (limit.rlim_cur == RLIM_INFINITY)
    68                  printf("(infinite) ");
    69          else{
    70                  lim = limit.rlim_cur;
    71                  printf("(infinite) ");
    72          }
    73
    74          if (limit.rlim_max == RLIM_INFINITY)
    75                  printf("(infinite)");
    76          else{
    77                  lim = limit.rlim_max;
    78                  printf("%10lld",lim);
    79          }
    80          putchar((int) '\n');
    81
    82  }



在linux上运行结果:

RLIMIT_AS      (infinite) (infinite)
RLIMIT_CORE    (infinite) (infinite)
RLIMIT_CPU     (infinite) (infinite)
RLIMIT_DATA    (infinite) (infinite)
RLIMIT_FSIZE   (infinite) (infinite)
RLIMIT_MEMLOCK (infinite)      65536
RLIMIT_MSGQUEUE (infinite)     819200
RLIMIT_NOFILE  (infinite)       1024
RLIMIT_RSS     (infinite) (infinite)
RLIMIT_SIGPENDING (infinite)     256701
RLIMIT_STACK   (infinite) (infinite)


0 0