OS-Final Exam
OS-Final Exam
Total
10 20 15 10 15 20 90
Marks
Marks
Obtained
semaphore spoon = 4;
while (!had_enough_to_eat())
{
wait(spoon);
wait(spoon);
eat();
signal(spoon);
signal(spoon);
}
(a) Can this dining plan lead to a deadlock? YES or NO. Explain your answer.
Answer:
int s;
int num_spoons = my_spoon_requirement();
while (!had_enough_to_eat())
{
for (s = 0; s < num_spoons; s++)
{
wait (spoon); /* May block. */
}
eat ( );
for (s = 0; s < num_spoons; s++)
{
signal (spoon); /* Does not block. */
}
}
What is the smallest number of spoons (in terms of D and S d) needed to ensure that deadlock cannot
occur? Explain your answer.
Answer:
Consider a Multilevel Feedback Queue Scheduler having three queues numbered from 1 to 3 (see Fig. A). The
processes are scheduled as follows:
A new process enters queue 1 which is served using Round Robin (RR). When it gains CPU, process
receives 8 milliseconds. If it does not finish in 8 milliseconds, process is moved to the end of queue
2.
If queue 1 is empty, the processes at queue 2 are served using RR and receives 16 milliseconds. If it
does not complete, it is preempted and moved to queue 3.
Processes in queue 3 are run on a First Come First Serve (FCFS) basis, but are run only when queues
1 and 2 are empty.
A process that arrives for queue 2 will preempt a process in queue 3. A process in queue 2 will in
turn be preempted by a process arriving for queue 1.
If a process does not use up its quantum in queue 2 due to preemption by queue 1, it will keep its
current queuing level and be put into the end of the queue. Then, it can still get the same amount of
quantum (not remaining quantum) next time when it is picked.
The following set of processes, with the arrival times and the length of the CPU‐burst times given in
milliseconds, have to be scheduled using this Multilevel Feedback Queue Scheduler:
(c) Calculate the average waiting time and the average turnaround time for the scheduling.
Consider a system with 20 bits logical address and 4 MBs main memory size and page size is 4 KBs.
E. Convert logical address into physical address (you have to provide its binary as well as decimal
representation).
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main( ) {
int n = 5;
pid_t pid;
if (pid == 0) {
if (i % 2 == 0) {
fork( );
printf ("Child process %d\n", i);
} else {
printf ("Child process %d\n", i);
fork( );
}
break;
} else if (pid > 0) {
wait (NULL);
printf ("Parent process\n");
} else {
printf ("Fork failed\n");
return 1;
}
}
return 0;
}
Answer:
A page fault to virtual page 4 has occurred. Which page frame will have its contents replaced for each of the
following memory management policies? Explain why in each case.
a) FIFO (first-in-first-out)
(a) Convert it to the matrix representation (i.e., Allocation, Request and Available)