zoukankan      html  css  js  c++  java
  • 4.8资源和限制

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <sys/time.h>
    #include <sys/resource.h>
    #include <sys/types.h>
    #include <unistd.h>


    static void work()
    {
    int i = 0;
    FILE *f;
    double x = 3.5;

    f = tmpfile();
    if(!f)
    {
      exit(0);
    }

    for(;i<1000;i++)
    {
      fprintf(f, "Do some output ");
      if(ferror(f))
      {
        fprintf(stderr, "Error writing to temporary file ");
        exit(1);
      }
    }

    for(i=0;i<1000000;i++)
    {
      x = log(x*x + 3.1);
    }

    }


    int main()
    {

      struct rusage r_usage;

      struct rlimit r_limit;

      int priority;

      work();

     //用户时间,系统时间cpu

      getrusage(RUSAGE_SELF, &r_usage);

      
      printf("user time: %ld.%06ld sys time: %ld.%06ld ", r_usage.ru_utime.tv_sec, r_usage.ru_utime.tv_usec,
      r_usage.ru_stime.tv_sec, r_usage.ru_stime.tv_usec);


      //优先级
      priority = getpriority(PRIO_PROCESS, getpid());
      printf("priority is: %d ", priority);


      //文件大小限制
      int rv = getrlimit(RLIMIT_FSIZE, &r_limit);
      if(-1 == rv)
      {
        printf("error ");
      }
      else
      {
        printf("soft = %ld hard = %ld ", r_limit.rlim_cur, r_limit.rlim_max);
      }


    }

  • 相关阅读:
    eclipse 插件编写(三)(转)
    eclipse 插件编写(二)
    eclipse 插件编写(一)(转)
    js 中的 this 关键字
    js中创建对象的几种方式
    js 如何中如何理解对象?
    项目中的小技巧
    王国维的诗
    uni-app 基础组件
    登庐山 毛
  • 原文地址:https://www.cnblogs.com/zhangxuan/p/5316559.html
Copyright © 2011-2022 走看看