TENTAMEN TDDI12 Operativsystem och Processprogrammering 2 po¨ ang

advertisement
TENTAMEN TDDI12
Operativsystem och Processprogrammering
2 poäng
August 16, 2006
LINJE:
TID:
Antal uppg.:
Antal poäng:
Hjälpmedel:
EI
14.00 – 18.00
9
68
Engelsk-Svensk-Engelsk ordbok, Miniräknare
Betygsgränser: U, G och VG
Underkänd: 0 – 33.9 p
G: 34 – 50.9 p
VG: 51 – 68 p
Betygsgränser: U, 3, 4 och 5
Underkänd: 0 – 33.9 p
3: 34 – 44.9 p
4: 45 – 55.9 p
5: 56 – 68 p
Skriv namn, klass och personnummer på samtliga lösa blad. I övrigt så gäller även
följande:
1. Endast ett svar per blad. Använd endast framsidan (delfrågor kan vara på samma
sida).
2. Sortera inlämnade svar med avseende på uppgiftsnummer i stigande ordning.
Poängavdrag kommer att göras om detta inte åtföljs!
Var vänlig och skriv tydligt och läsbart. Poäng kommer inte att ges till oläsbara svar.
Svaren får vara på svenska och/eller engelska.
Dina svar skall tydligt visa lösningsmetod. Enbart rätt svar kommer inte att ge poäng.
I det fall du är osäker på frågeställning, skriv ner din tolkning och lös uppgiften utifrån
din tolkning.
Lycka till!
1
1 Operating Systems (11 points)
a) (4 points): Name the five states of a process with regard to process management.
Draw the diagram of process state for a time-shared operating system and name
all transitions between different states.
b) Architecture (3 points): Explain in relation to operating systems what is the user
mode and the monitor/kernel mode. How is it implemented on recent hardware?
Provide and motivate some instructions that usually run in i) user mode and ii)
monitor mode.
c) System call (4 points): An important concept in Operating Systems is the system
call. Explain what is a system call, its purpose, and why operating systems provide
different system calls. How did system calls improve the way of writing software
applications?
2 Processes and Threads (4 points)
a) (4 points): Describe the actions taken by a kernel to switch context between processes. Draw a (time) diagram that shows what actions occur during a context
switch. Give and motivate several situations when and why context switch occurs.
3 Scheduling (7 points)
a) (7 points): Consider the following set of processes, with the length of the CPUburst time, and their arrival time given in milliseconds:
Process
P1
P2
P3
P4
P5
Arrival Time
3
2
4
3
0
Burst Time
10
1
2
1
5
Priority
3
1
3
4
2
i) (2 points): Draw four Gantt charts illustrating the execution of these processes using First Come First Served (FCFS), preemptive Shortest Job First
(SJF), a non-preemptive priority (a smaller priority number implies a higher
priority), and Round Robin (RR) (quantum of 1ms) scheduling. If multiple
choice occurs, prefer the process with higher priority. For the RR, assume
that processes arrive in the queue a fraction of ms before their arrival time.
ii) (2 points): What is the turnaround time of each process for each of the
scheduling algorithms in part i)?
iii) (2 points): What is the waiting time of each process for each of the scheduling
algorithms in part i)?
2
iv) (1 point): Which of the schedules in part i) results in the minimal average
waiting time (over all processes)?
4 Synchronization (10 points)
a) Deadlock (1 point): What is a deadlock?
b) Dining-philosophers problem (5 points):
• A philosopher spends his life in either thinking or eating.
• Consider five philosophers sitting around a table. In front of each philosopher
there is a bowl with spaghetti. When a philosopher gets hungry he/she picks
up his/her left, then his/her right fork and starts eating from his/her bowl.
• Once a philosopher is done with the food, he/she puts back both forks on the
table and thinks again.
Consider the following algorithm:
semaphore forks[5] = {1, 1, 1, 1, 1};
while(1) {
wait(forks[i]);
...
eat();
...
think();
}
Each fork is modeled by a semaphore. A philosopher i has to acquire his/her left
fork (forks[i]) and his/her right fork before eating.
i) (1 point): Copy the code above to your solution sheet and fill in the missing
operations.
ii) (1 point): Is this code subject to deadlock? (Explain why or why not.)
iii) (1 point): Draw the resource allocation graph for the above problem.
iv) (2 points): Propose a method to avoid the deadlock. Motivate why it works
and modify the code accordingly.
c) Concurrent programming (4 points): What are the problems that may occur with
concurrent programming? What are the facilities available in most modern operating systems and development (API) for concurrent programming? You should
show a motivating example of solving a synchronization problem.
3
5 Memory Management and Virtual Memory (13 points)
a) (4 points): What is the purpose of a memory management unit (MMU) in a virtual
memory system? Draw a diagram and explain in details how the MMU works.
b) (2 points): For each of the following decimal addresses, compute the virtual page
number and the offset for a 4KB (K Byte) and 8KB page: 40000; 32768; 120000
(observe, 1k=210 ).
c) (3 points): In a two-level paging system where the first level uses 8 bits, the second
level uses 14 bits, and the page offset uses 10 bits.
i) (1 point): How many frames uses a program of 42Mb (M = K · K; K =
1024 = 210 ), and the page tables if every thing is in memory.
ii) (1 point): What is the memory overhead due to the paging in case i) in terms
of data accesses?
iii) (1 point): What is the memory overhead due to the paging in case i) in terms
of storage?
d) (4 points): Consider the following page-reference string:
1, 3, 2, 5, 4, 2, 1, 5, 6, 3, 2, 1, 2, 6, 3, 2, 1, 2, 3, 6
How many page faults would occur for the following replacement algorithms assuming one, four, and six frames?
i) LRU (Least Recently Used) replacement;
ii) FIFO (First In First Out) replacement;
iii) Optimal replacement.
6 Deadlock (6 points)
a) (4 points) Consider a system with a total of 150 units of memory, allocated to
three processes as shown:
Process
1
2
3
Max
70
60
60
Hold
45
40
15
Apply the banker’s algorithm (see Appendix) to determine whether it would be safe
to grant each of the following requests. If yes, indicate a sequence of terminations
that could be guaranteed possible. If no, show the reduction of the resulting
allocation table.
4
i) A fourth process arrives, with a maximum memory need of 60 and an initial
need of 25 units.
ii) A fourth process arrives, with a maximum memory need of 60 and an initial
need of 35 units.
b) (2 points) Consider a system consisting of four processes and a single resource.
The current state of the claim (C) and allocation (A) matrices is:
C=
3
2
9
7
A=
1
1
3
2
What is the minimum number of units of the resource needed to be available for
this state to be safe? (Justify your answer).
7 Security and Protection (3 points)
a) (1 point): Assume that passwords are limited to the use of the 95 printable ASCII
characters and that all passwords are 10 characters in length. Assume a password
cracker with an encryption rate of 6.4 million encryptions per second. How long
will it take to test exhaustively all possible passwords on such a system?
b) (1 point): In UNIX, rights to various objects of protection (e.g. files) are granted
to individual users, to groups of users determined in advance by the system administrator, and to all users of the system. Give a simple example of a situation
where this is not flexible enough.
c) (1 point): What are two advantages of encrypting data stored in the computer
system?
8 Real-time Operating Systems (8 points)
a) (4 points): Enumerate several characteristics of a real-time operating systems.
Explain for instance why a layered design of is not suitable for a real-time OS.
Why usually there is no virtual memory on real-time OS?
b) (2 points): Give several applications area where:
i) a hard real-time scheduling is more appropriate
ii) a soft real-time scheduling is more appropriate
c) (2 points): (This exercise is from course book)
Consider two processes: P1 and P2 , where the period for P1 is p1 = 50 (resp. for
P2 is p2 = 75) and the processing time for P1 is t1 = 25 (resp. for P2 is t2 = 30).
5
i) Can these two processes be scheduled using rate-monotonic scheduling? Illustrate your answer using Gantt chart.
ii) Illustrate the scheduling of these two processes using Earliest-Deadline First
(EDF) scheduling.
9 Quiz (6 points)
In this multiple choice questions correct answer gives 0.5 point and wrong answer retrieves 0.5. No answer gives 0 point (no subtraction in case of no answer). The questions
are on next page. Please cross the circles and return the last paper sheet with your exam.
6
Please, cross the circles and return this paper sheet.
Right
Wrong
Question
The setuid bit indicates if a user has or has not a valid id.
With Round Robin Scheduling, processes are subject to starvation.
Aging is a technique to provide starvation.
A MULTIPLY (MUL) instruction is usually privileged.
A dirty bit indicates if a frame has been modified or not.
Demand paging affects on the performance of a computer system.
A CPU-bounded process has long CPU bursts.
A typical mobile phone does not need an OS.
UNIX directory structure cannot be graphs.
The term “Denial of Service” indicates that a user with insufficient privileges tries to access a forbidden resource.
Systems designed for graceful degradation are also called fault
tolerant.
A part of a program where system calls occur is called a “critical region”.
7
Appendix
The appendix recall the algorithms from Chapter 8 Deadlocks.
Safety Algorithm
1. Let Work and Finish be vectors of length m and n, respectively.
Initialize Work:=Available and Finish[i]:=false for i=1,2,...,n.
2. Find an i such that both
a. Finish[i] = false
b. Need_i <= Work
If no such i exists, go to step 4.
3. Work:=Work+Allocation_i
Finish[i]:=true
go to step 2.
4. If Finish[i]=true for all i, then the system is in a safe state.
Resource-Request Algorithm
1. If Request_i <= Need_i, go to step 2. Otherwise, raise an error
condition, since the resources are not available.
2. If Request_i <= Available, go to step 3. Otherwise, P_i must wait,
since the resources are not available.
3. Have the system pretend to have allocated the requested resources
to process P_i by modifying the state as follows:
Available:=Available - Request_i;
Allocation_i:=Allocation_i + Request_i;
Need_i:=Need_i - Request_i;
If the resulting resource-allocation state is safe, the transaction
is completed and process P_i is allocated its resources. However,
if the new state is unsafe, then P_i must wait for Request_i and
the old resource-allocation state is restored.
Deadlock Detection Algorithm
1. Let Work and Finish be vectors of length m and n, respectively.
Initialize Work:=Available. For i=1,2,...,n, if Allocation_i != 0,
then Finish[i]:=false; otherwise, Finish[i]:=true.
2. Find an i such that both
a. Finish[i] = false
b. Need_i <= Work
If no such i exists, go to step 4.
3. Work:=Work+Allocation_i
Finish[i]:=true
go to step 2.
4. If Finish[i]=false, for some i, 1 <= i <= n, then the system is in
a deadlock state. Moreover, if Finish[i]=false, then process P_i is
deadlocked.
8
Download