Question: #define _GNU_SOURCE #include #include #include #include #include #include #include void setCPU() { cpu_set_t myCPUs; //CPU_ZERO(&myCPUs); //sched_getaffinity(0,sizeof(cpu_set_t),&myCPUs); //int p = CPU_COUNT(&myCPUs); CPU_ZERO(&myCPUs); CPU_SET(0,&myCPUs); if( sched_setaffinity(0,sizeof(cpu_set_t),&myCPUs) ==

#define _GNU_SOURCE

#include

#include

#include

#include

#include

#include

#include

void setCPU()

{

cpu_set_t myCPUs;

//CPU_ZERO(&myCPUs);

//sched_getaffinity(0,sizeof(cpu_set_t),&myCPUs);

//int p = CPU_COUNT(&myCPUs);

CPU_ZERO(&myCPUs);

CPU_SET(0,&myCPUs);

if( sched_setaffinity(0,sizeof(cpu_set_t),&myCPUs) == -1 )

perror("cant change the cpu affinity of the process:");

else

{

//sched_getaffinity(0,sizeof(cpu_set_t),&myCPUs);

//p = CPU_COUNT(&myCPUs);

//printf("Num CPUs in set %d ", p);

}

//printf("The scheduling priority of the process is %d ", sched_getscheduler(0));

}

int main()

{

//setCPU();

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 ", p);

while( wait(NULL) != -1);

return 0;

}

This homework deals with scheduling on Linux. Consider the code shown above

a) Describe what is happening in main()?

b) Run the program on ale and submit the output.

c) Describe why are you getting the output you are getting even though the processes have a particular pattern of static scheduling priorities? It would help to know that ale has 40 CPU cores.

d) Describe what is happening in setCPU() function. Ignore the commented code.

e) Uncomment the setCPU() call in main(). Run the program on ale. Submit the output.

f) How does the output in part e) differ from the output in part b)? Why?

g) The code never calls setCPU() on the child processes. So, how come the child processes are restricted to executing on CPU 0 only?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!