TENTAMEN TDDB63 Operativsystem och Processprogrammering 2 po¨ ang

advertisement
TENTAMEN TDDB63
Operativsystem och Processprogrammering
2 poäng
January 12, 2005
LINJE:
TID:
Antal uppg.:
Antal poäng:
Hjälpmedel:
DI, EI, I, Ii
08.00 – 12.00
7
60
Engelsk-Svensk-Engelsk ordbok, Miniräknare
Betygsgränser:
• Godkänd: runt 30 poäng och över
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!
Most of the problems were selected from the following books:
• Operating Systems (5th Edition) by William Stallings.
• The Architecture of Computer Hardware and Systems Software : An Information Technology Approach by Irv Englander
1
1 Operating Systems (12 points)
1. (2 points) An operating system is described as an event-driven program. What is
meant by event-driven? Explain how the dispatching operation fits this description?
2. (1 point) What is the advantage of separating file system from I/O services?
3. (2 points) What is the purpose of system calls, and how do system calls relate
to the operating system and to the concept of dual-mode (kernel mode and user
mode) operation?
4. (3 points) Explain the differences between multiprogramming, multiuser and multiprocessing.
5. (4 points) Discuss the steps that take place when a process is moved
a)
b)
c)
d)
from
from
from
from
ready queue state to running state,
running state to blocked state,
running state to ready state,
blocked state to ready state.
2 Scheduling (10 points)
1. (2 points) Develop an example that explains trashing clearly.
2. (2 points) Assume a simple priority scheduling. The priority for a process is computed as the ratio of the CPU time actually used by the process to the real time
that has passed. The lower the figure, the higher the priority. Priorities are recalculated every tenth of second.
a) What kind of jobs are favored by this type of algorithm?
b) If there is no I/O being performed, this algorithm reduces to round-robin
algorithm. Explain.
3. (6 points) Suppose that we have a multiprogrammed computer in which each job
has identical characteristics. In one computation period, T , for a job, half the time
is spent in I/O and the other half in processor activity. Each job runs for a total
of N periods. Assume that a simple round-robin scheduling is used, and that I/O
operations can overlap with processor operation.
• Define the following quantities: Turnaround time, Throughput, and Processor
utilization.
• Compute these quantities for one, and two simultaneous jobs, assuming that
the period T is distributed in each of the following ways: a) I/O first half,
processor second half; b) I/O first and fourth quarters, processor second and
third quarters.
2
3 Synchronization (8 points)
1. (6 points) Consider the following program:
const int n = 50;
int tally;
void total() {
int count;
for(count = 1; count <= n; count++) {
tally++;
}
}
void main(void) {
tally = 0;
start in parallel(total(), total());
printf(”%d”, tally);
}
a) (2 points) Determine the lower bound and upper bound on the final value
of the shared variable tally output by this concurrent program. Assume
processes can execute at any relative speed and that a value can only be
incremented after it has been loaded into a register by a separate machine
instruction.
b) (2 points) Suppose that an arbitrary number of these processes are permitted
to execute in parallel under the assumptions of part a). What effect will this
modification have on the range of final value of tally?
c) (2 points) Write a synchronized version of the program that assure to reach
the upper bound at each run with the assumptions of part a). (Assume that
you have access to most common synchronization primitives in the system).
2. (2 points) Consider the following program:
boolean blocked[2];
int turn;
void P(int id) {
while(true) {
blocked[id] = true;
while(turn != id) {
while(blocked[1-id])
/* do nothing */;
turn = id;
}
/* critical section */
blocked[id] = false;
/* reminder section */
}
}
void main(void) {
blocked[0] = false;
blocked[1] = false;
turn = 0;
start in parallel(P(0), P(1));
}
This software solution to the mutual exclusion problem for two processes is proposed in Hyman, H. “Comments on a Problem in Concurrent Programming Control.”, ACM, January 1966. Find a counterexample that demonstrates that this
solution is incorrect.
3
4 Deadlock (6 points)
1. (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.
a) A fourth process arrives, with a maximum memory need of 60 and an initial
need of 25 units.
b) A fourth process arrives, with a maximum memory need of 60 and an initial
need of 35 units.
2. (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).
5 Memory Management and Virtual Memory (11 points)
1. (2 points) A computer has a cache, main-memory, and a disk used for virtual
memory. If a referenced word is in the cache, 20 ns are required to access it. If it
is in main-memory but not in the cache, 60 ns are needed to load it into the cache
(this includes the time to originally check the cache), and then the reference is
started again. If the word is not in main-memory, 12 ms are required to fetch the
word from disk, followed by 60 ns to copy it to the cache, and then the reference
is started again. The cache hit ratio is 0.9 and the main-memory hit ratio is 0.6.
What is the average time in ns required to access a referenced word on this system?
2. (3 points) You are assigned to implement a page replacement algorithm in SOS
(Student Operating System). SOS provides you 3 frames per process. A typical
references string for processes executing on SOS is: 1, 2, 4, 2, 5, 3, 2, 1, 3, 5, 1.
For the questions, assume that initially all frames are empty.
4
a) Which page replacement algorithm among these two: LRU (Least Recently
Used), and FIFO (First In First Out); would you implement if you want to
minimize the page fault rate for the typical references string?
b) What is the minimal page fault rate for this system and the references string?
(Justify).
3. (1 point) Consider a fixed memory partitioning scheme with equal-size partitions of
216 bytes and a total main-memory size of 224 bytes. A process table is maintained
that includes a pointer to a partition for each resident process. How many bits are
required for the pointer?
4. (5 points) Consider a simple paging system with the following parameters: 232
bytes of physical memory; page size of 210 bytes; 216 pages of logical address
space.
a) How many bits are in a logical address?
b) How many bytes in a frame?
c) How many bits in the physical address specify the frame?
d) How many entries in the page table?
e) How many bits in each page table entry? Assume each page table entry
includes a valid/invalid bit.
6 File System (10 points)
1. (2 points) Explain why a MOVE operation from one device to another requires
manipulation of the file itself, whereas a MOVE operation from one place to another
on the same device involves manipulation only of the directory.
2. (2 points) List a number of types of files that you would expect to be accessed
sequentially. Do the same for files that you would require random access.
3. (1 point) What is the transfer rate of a nine-track magnetic tape unit, whose tape
speed is 0.25 m per second and whose tape density is 800 linear bits per centimeter?
4. (2 points) Consider a hierarchical file system in which free disk space is kept in a
free space list.
a) Suppose the pointer to free space is lost. Can the system reconstruct the free
space list?
b) Suggest a scheme to ensure that the pointer is never lost as a result of a single
memory failure.
5. (3 points) Consider the UNIX i-node with the following entries:
5
mode (4 bytes)
owners (8 bytes)
timestamps (12 bytes)
size block (4 bytes)
count (4 bytes)
direct blocks (4 bytes)
direct blocks (4 bytes)
···
single indirect (4 bytes)
double indirect (4 bytes)
Assume that pointed indirect blocks have only direct pointers or indirection pointers, and the size of an i-node is the size of the block. Draw the i-node representation
on which you base your calculations.
How many disk blocks can be addressed on a system with a block size of 4kB (kilo
bytes, 1k = 210 ) using:
a) just direct indexing?
b) just direct and single indirect indexing?
c) all indexing (direct, single and double)?
7 Security and Protection (3 points)
1. (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?
2. (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.
3. (1 point) What are two advantages of encrypting data stored in the computer
system?
6
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.
7
Download