为什么在1ns间隔内轮询时cpu负载太低

问题描述

#include <stdio.h>
#include <time.h>

int main()
{
    struct timespec stReq;
    stReq.tv_sec = 0;
    stReq.tv_nsec = 1;
    while(1)
    {
        nanosleep(&stReq,NULL);
        printf("hello,world\n");
    }

    return 0;
}

运行此进度时,%cpu显示top列大约只有2%

为什么这么低?

解决方法

  1. 因为该程序无所事事
  2. 您的系统具有足够好的cpu内核。
  3. 它将在cpu的哪一部分显示2%?我们,sy,id,wa,st?