日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux程序无法获取cpu资源,Linux系统编程获取系统的CPU资源

發(fā)布時間:2024/9/27 linux 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux程序无法获取cpu资源,Linux系统编程获取系统的CPU资源 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

還是純干貨,代碼拿來:

#include

#include

#include

#include

#include

#include

#include

void work()

{

FILE *f;

int i;

double x = 4.5;

f = tmpfile();

for(i = 0; i < 10000;i++)

{

fprintf(f,"Do some output\n");

if (ferror(f))

{

fprintf(stderr,"Error writing to temporary file\n");

exit(1);

}

}

for (i =0; i < 1000000; i++)

x = log(x*x + 3.21);

}

int main()

{

struct rusage r_usage;

struct rlimit r_limit;

int priority;

work();

getrusage(RUSAGE_SELF, &r_usage);

printf("CPU usage: User = %ld.%6ld, 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);

priority = getpriority(PRIO_PROCESS, getpid());

printf("Current priority = %d\n", priority);

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);

}效果如圖所示:

總結(jié)

以上是生活随笔為你收集整理的linux程序无法获取cpu资源,Linux系统编程获取系统的CPU资源的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。