I have a sh script:
#!/bin/sh
taskset -c 1 ./RR_FIFO_sched 2 90 &
taskset -c 1 ./RR_FIFO_sched 2 90 &
sleep 5s
taskset -c 1 ./RR_FIFO_sched 2 95 &
exit
And the code in the source file named RR_FIFO_sched.c:
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int main(int argc, char *argv[])
{
long i, j, temp;
char cmd_str[100];
int rc, current_scheduler_policy;
struct sched_param my_params;
if (argc != 3) {
printf("Usage:RR-FIFO-sched sched_class priority \nsched_class: 0 for CFS; 1 for FIFO; 2 for RR\n");
exit(1);
}
my_params.sched_priority = atoi(argv[2]);
rc = sched_setscheduler(0, atoi(argv[1]), &my_params);
if (rc < 0) {
perror("sched_setscheduler error\n");
exit(0);
}
current_scheduler_policy = sched_getscheduler(0);
printf("the PID:%d current scheduler = %d \n", getpid(), current_scheduler_policy);
for (i = 0; i < 1024 * 1024 * 1024; i++)
for (j = 0; j < 10; j++)
temp++;
sprintf(cmd_str, "cat /proc/%d/sched > ./sched-%d ; date >> ./sched-%d",
getpid(), getpid(), getpid());
system(cmd_str);
return 0;
}
I was going to create two RR processes with a priority of 90 at the same time and let them do simple calculations and compete for the CPU#1. Five seconds later, I would create a FIFO process with a priority of 95.In my imagination, the FIFO process will interrupts the first two processes and monopolizes CPU#1. After the FIFO process finishes, the two RR processes regain the CPU. Then with running the script on the terminal and observing with the top command on another terminal, I found that the system created processes one by one instead of creating two processes at the same time. So Why did that happend? I would appreciate it deeply if you would anwser this question for me.