Assignment: Operating Systems
Answer the following:
1. Consider a preemptive priority scheduling algorithm based on dynamically changing priorities. Greater priority numbers imply higher priority. When a process is waiting for the CPU (in the ready queue, but not running), its priority changes at a rate R; when it is running, its priority changes at a rate E. All processes are given a priority of 0 when they enter the ready queue. Explain how the processes are scheduled (that is, how they are ordered, or, what type of scheduling algorithm is this) when R < E < 0. Explain your answer.
2. Measurements of certain system have shown that the average process runs for a time R before blocking for an I/O. If processes on the system are scheduled using the round-robin algorithm with quantum time Q, where Q < R, then derive an expression for CPU efficiency. It is known that the context-switch time on the system is X (which is < Q).
(Hint: CPU efficiency can be calculated as actual execution time/total time, where total time includes all context switch overheads and execution.)
3. Consider the following codes of two processes sharing a variable turn that is initialized to 1.
a. Does this satisfy mutual exclusion condition? Explain.
b. Is it a good solution to critical region problem? Explain.
Process P0
|
Process P1
|
/* other code */ while (turn != 0){ } /* wait */ update(); /* critical region */ turn = 0; /* other code */
|
/* other code */ while (turn != 1){ } /* wait */ update(); /* critical region */ turn = 1; /* other code */
|
4. Suppose there are two processes - i and j, sharing variables turn and flag[2]. Consider the following code for process i. Process j has similar code.
do {
flag[i] = true;
while (flag[j]) {
if (turn == j) {
flag[i] = false;
while (turn == j); /* do nothing */
flag[i] = true;
}
}
critical_task(); /* critical region */
turn = j;
flag[i] = false;
other_tasks(); /* remainder section */
}while (true);
Explain whether the above solution satisfy all conditions of critical region problem for two processes.