码迷,mamicode.com
首页 > 其他好文 > 详细

资源和限制

时间:2015-09-23 01:03:31      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:

#include  <sys/types.h>
#include  <sys/resource.h>
#include  <sys/time.h>
#include <stdio.h>
#include  <unistd.h>
#include <stdlib.h>
#include  <math.h>
void work()
{
    FILE *f=tmpfile();
    for(int i=0;i<10000;++i)
    {
        fprintf(f,"Do something output\n");
        if(ferror(f))
        {
            fprintf(stderr,"Error writing to temporary file\n");
            exit(1);
        }
    }
    double x=4.5;
    for(int i=0;i<1000000;++i)
        x=log(x*x+3.21);
}

int main(int argc,char * argv[])
{
    struct rusage r_usage;
    work();
    getrusage(RUSAGE_SELF,&r_usage);
    printf("CPU usage:User = %ld. %06ld, System=%ld. %06ld\n",
           r_usage.ru_utime.tv_sec,r_usage.ru_utime.tv_usec,
           r_usage.ru_stime.tv_sec,r_usage.ru_stime.tv_usec);
    int priority;
    priority = getpriority(PRIO_PROCESS,getpid());
    printf("Current priority = %d\n",priority);
    struct rlimit r_limit;
    getrlimit(RLIMIT_FSIZE,&r_limit);
    printf("Current FSIZE limit : soft = %ld,hard = %ld\n",
           r_limit.rlim_cur,r_limit.rlim_max);
    r_limit.rlim_cur=2048;
    r_limit.rlim_max=4096;
    printf("Setting a 2K file size limit\n");
    setrlimit(RLIMIT_FSIZE,&r_limit);
    work();
    exit(0);
}


资源和限制

标签:

原文地址:http://www.cnblogs.com/cqhstyle/p/4830966.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!