具有40个CPU内核的静态调度优先级?

时间:2017-11-13 23:27:48

标签: c scheduling

#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <sched.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <limits.h>

int main()
{
    int i = 1;
    while( i < 20 )
    {
        if( fork() == 0 )
        {
            setpriority(PRIO_PROCESS,0,i);
            break;
        }
        i++;
    }

    i = 0;
    while( i <= 0.9*INT_MAX )
        i++;

    int p = getpriority(PRIO_PROCESS,0);
    printf("priority %d\n", p);

    while( wait(NULL) != -1);
    return 0;
}

输出:

priority 10
priority 12
priority 16
priority 14
priority 6
priority 3
priority 15
priority 8
priority 5
priority 1
priority 4
priority 0
priority 2
priority 18
priority 7
priority 17
priority 19
priority 9
priority 13
priority 11

这个输出是由main()生成的,我无法找到为什么我得到这个输出,即使进程有一个特定模式的静态调度优先级并且有40个CPU内核?

另外,第二个wile循环while( i <= 0.9*INT_MAX )是否像定时器函数或随机函数一样?

0 个答案:

没有答案