Professional Documents
Culture Documents
Answer:
The short-term scheduler selects from the ready processes the next process to run
and gives it the CPU. The long-term scheduler selects from the pool of processes
that are waiting on disk and loads the selected process(es) into memory. These
processes have not yet begun their execution. The medium-term scheduler takes
processes that are currently in memory and selects those to be swapped out to
disk. These processes will be swapped back in at a later point. This is done to
improve process mix or because of memory requirements (i.e., overcommitted
and needs to free up memory).
3.2 The kernel saves the state of the currently executing process into its Process
Control Block (PCB ). The state includes the values of all registers, process ID,
memory information, list of open files, and so forth. It then reloads the context of
a previously suspended process and sets the instruction counter to the restored
processes next instruction.
3.4 The output will be Parent: Value = 5. Once the child process has forked, it is no
longer connected to the parent (i.e., the child will have all of the variables and
values of the parent when the fork is complete, but they will no longer share
memory), so the update to the variable value does not effect the parent.
3.5 What are the benefits and detriments of each of the following? Consider
both the systems and the programmers levels.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
int main(int argc, char *argv[])
{ pid_t pid;
int i, a, b, n, fib;
if (argc != 2)
exit(0);
n = atoi(argv[1]);
if (n < 0)
{printf(Error in Input\n) ;
exit(0) ;
}
/* fork another process */
pid = fork();
if (pid < 0)
{ /* error occurred */
fprintf(stderr, "Fork Failed\n");
exit(-1);
}
else if (pid == 0)
{ /* I am child process */
if (n == 1)
printf("0\n");
else if (n == 2)
printf("0, 1\n");
else if (n > 2)
{a = 0;
b = 1;
for (i = 3; i < n; i++)
{fib = a + b;
printf("%d,",fib);
a = b;
b = fib;
}
printf("%d\n",a+b);
}
}
else { /* parent process */
wait(NULL);
}
}
Note: I am not concerned with whether you know how to generate fionacci
numers but rather that you know how to get the parameter from the
command line and how to fork a child process.
5.2 Discuss how the following pairs of scheduling criteria conflict in
certain settings.
a. CPU utilization and response time
b. Average turnaround time and maximum waiting time
c. I/O device utilization and CPU utilization
Answer:
The processes are assumed to have arrived in the order P1, P2, P3, P4, P5,
all at time 0.
b. What is the turnaround time of each process for each of the scheduling
algorithms in part a?
c. What is the waiting time of each process for each of the scheduling
algorithms in part a?
d. Which of the schedules in part a results in the minimal average waiting
time (over all processes)?
FCFS
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
P1 P2 P3 P4 P5
SJF
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
P2 P4 P3 P5 P1
Non-preemptive
Priority
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
P2 P5 P1 P3 P4
RR Quantum = 1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
b. Turnaround time
P1 10 19 19 16
P2 11 2 1 1
P3 13 7 4 18
P4 14 4 2 19
P5 19 14 9 6
5.6 Consider a variant of the RR scheduling algorithm where the entries in the
ready queue are pointers to the PCBs.
a. What would be the effect of putting two pointers to the same process in
the ready queue?
b. What would be the major advantages and disadvantages of this
scheme?
c. How would you modify the basic RR algorithm to achieve the same
effect without the duplicate pointers?
Answer:
a. In effect, that process will have increased its priority since by getting
time more often it is receiving preferential treatment.
b. The advantage is that more important jobs could be given more time, in
other words, higher priority in treatment. The consequence, of course, is
that shorter jobs will suffer.
5.7 Consider a system running ten I/O-bound tasks and one CPU-bound task.
Assume that the I/O-bound tasks issue an I/O operation once for every
millisecond of CPU computing and that each I/O operation takes 10
milliseconds to complete. Also assume that the context switching
overhead is 0.1millisecond and that all processes are long-running tasks.
What is the CPU utilization for a round-robin scheduler when:
Answer:
Answer: The program could maximize the CPU time allocated to it by not
fully utilizing its time quantums. It could use a large fraction of its
assigned quantum, but relinquish the CPU before the end of the quantum,
thereby increasing the priority associated with the process.
5.10 Explain the differences in the degree to which the following scheduling
algorithms discriminate in favor of short processes:
a. FCFS
b. RR
c. Multilevel feedback queues
Answer:
b. RRtreats all jobs equally (giving them equal bursts of CPU time)
so short jobs will be able to leave the system faster since they will
finish first.
Priority = (Recent CPU usage / 2) + Base where base = 60 and recent CPU
usage refers to a value indicating how often a process has used the CPU
since priorities were last recalculated.
Assume that recent CPU usage for process P1 is 40, process P2 is 18, and
process P3 is 10. What will be the new priorities for these three processes
when priorities are recalculated? Based on this information, does the
traditional UNIX scheduler raise or lower the relative priority of a CPU-bound
process?
Answer: The priorities assigned to the processes are 80, 69, and 65
respectively. The scheduler lowers the relative priority of CPU-bound
processes.