我正在学习Linux调度程序。首先,我要测试FIFO调度程序。这是我用来测试的代码:
#include <sched.h>
#include <stdio.h>
int main(int argc, char **argv)
{
printf("Setting SCHED_FIFO and priority to %d\n",atoi(argv[1]));
struct sched_param param;
param.sched_priority = atoi(argv[1]);
sched_setscheduler(0, SCHED_FIFO, ¶m);
int n = 0;
while(1) {
n++;
if (!(n % 10000000)) {
printf("%s FIFO Prio %d running (n=%d)\n",argv[2], atoi(argv[1]),n);
}
}
}
我在2个终端上以优先级1运行该程序:./main 1
。因为我的CPU只有1个内核,所以由于FIFO属性,我预计只有第一个终端可以运行。但是,在实际测试中:两个终端都可以运行代码。
这是我运行命令lscpu
时的CPU信息:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 85
Model name: Intel(R) Xeon(R) Gold 6140 CPU @ 2.30GHz
Stepping: 4
CPU MHz: 2294.608
BogoMIPS: 4589.21
Virtualization: VT-x
Hypervisor vendor: KVM
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 4096K
请为我解释原因。