TENTAMEN / TDDI04 / TDDI12 / TDDB63 Processprogrammering, operativsystem och realtidsoperativsystem /

advertisement
Linköpings universitet
IDA Department of Computer and Information Sciences
Doc. Christoph Kessler
TENTAMEN / EXAM
TDDI04 / TDDI12 / TDDB63
Processprogrammering, operativsystem och
realtidsoperativsystem /
Concurrent programming, operating systems and real-time
operating systems
31 may 2007, 14:00–18:00, TER1
Jour: Vlad Jahundovics (013-282747, 070-7103304);
Christoph Kessler (on travel; in urgent cases: 070-3666687 before 16:30)
Hjälpmedel / Admitted material:
– Engelsk ordbok / Dictionary from English to your native language;
– Miniräknare / Pocket calculator
General instructions
This exam has 10 assignments and 5 pages, including this one.
Read all assignments carefully and completely before you begin.
It is recommended that you use a new sheet for each assignment. Number all your sheets,
and mark each sheet on top with your name, personnummer, and the course code.
You may answer in either English or Swedish.
Write clearly. Unreadable text will be ignored.
Be precise in your statements. Unprecise formulations may lead to a reduction of points.
Motivate clearly all statements and reasoning.
Explain calculations and solution procedures.
The assignments are not ordered according to difficulty.
The assignment named Real-Time Operating Systems should be solved by TDDI04
and TDDI12 students.
TDDB63 students solve instead the assignment named For TDDB63 only.
The exam is designed for 40 points. You may thus plan about 5 minutes per point.
Grading: U, 3, 4, 5. The preliminary threshold for passing is 20 points.
For exchange students (with a ’P’ in the personnummer), ECTS marks will be applied.
1
1. (3 p.) Processes and threads
Define the three terms process, kernel thread and user thread, and explain the differences
between these. (3p)
2. (6 p.) Synchronization
Consider an ordinary hash table T of size M designed for a single-threaded environment.
A hash function h that maps data items to the range f0 ::: M ; 1g is given. Data items
u v hashed to the same hash value h(u) = h(v) = i are chained in a singly-linked list,
such that list T i] contains all items with hash value i (see the picture). Each list item
contains a data element and a next pointer to the next item in the list (NULL for the last
element in a list). Each T i] points to the first item in its list (or T i] is NULL if the ith
list is empty), i = 0 ::: M ; 1.
T
0
M−1
(a) As a starting point, give ordinary unprotected (pseudo)code for the operation
insert(T u) that inserts a data item u into hash table T at the beginning of list
T h(u)], and for the boolean operation lookup(T u) that checks whether item u is
currently stored in T or not. (You can assume that a boolean function equal(u v )
is given that tests for equality of two data items u and v .) (1p)
(b) Give an example scenario of a race condition with two threads that concurrently insert items into an unprotected shared hash table on a multi-tasking single-processor
system – i.e., give two different interleavings of the execution of two threads that
lead to different results, possibly even to a corrupted data structure or a run-time
error. (2p)
Your task will now be to make the hash table implementation thread-safe to allow a
hash table stored in shared memory to be accessed properly by multiple threads:
(c) Identify the critical section(s) in your pseudocode and suggest how to protect them
against race conditions using one or several mutex locks (show the revised (pseudo)
code). (2p)
Note: There are actually two different strategies for doing this. What is the disadvantage of a single-lock strategy if there are many threads accessing T frequently,
and why? What is the better alternative? (+1p)
(d) Threads executing an insert operation modify the status of T , while threads executing a lookup do not change it. Assume that lookup operations occur much
more often than insert operations. Suggest a lock-based protection technique
2
that exploits this fact to improve the degree of concurrency compared to your previous solution. (No details, no code. Just give the technical term and the basic idea
how it works.) (1p)
3. (5 p.) CPU Scheduling
Given a single-CPU system and the following set of processes with arrival times (in
milliseconds), expected maximum execution time (ms), and priority (1 is highest, 5 is
lowest priority).
Process
P1
P2
P3
P4
P5
Arrival time
0
2
3
5
6
Execution time
4
7
5
2
1
Priority (as applicable)
3
2
1
5
4
For each of the following scheduling algorithms, create a Gantt chart (time bar diagram,
starting at t = 0) that shows when the processes will execute on the CPU. Where applicable, the time quantum will be 3 ms. (5p)
(i) FIFO;
(ii) Round-robin;
(iii) Shortest Job First without preemption;
(iv) Priority Scheduling without preemption.
(v) Priority Scheduling with preemption.
4. (5 p.) Deadlocks
(a) There are four conditions that must hold for a deadlock to become possible. Name
and describe them briefly. (2p)
(b) You are given a system with 4 types of resources, A, B , C and D . There are 3
instances of A, 5 instances of B , 2 instances of C and 6 instances of D . Currently,
4 processes P1 ...P4 are running, and for each process, the resources currently held
and its total maximum resource need for each type are given as follows:
Process Already held Maximum total need
P1
P2
P3
P4
ABCD
ABCD
1 2 2 0
2 2 2 3
0 1 0 1
0 2 0 4
1 0 0 2
2 2 0 3
0 0 0 2
1 0 1 4
(i) Show that the system is currently in a safe state (calculation). (1.5p)
(ii) Process P2 now asks for 1 instance of B and 1 of D. Can the request be granted?
Why or why not? (calculation) (1.5p)
3
5. (6 p.) Memory management
(a) Define internal fragmentation and external fragmentation in allocation of (physical)
memory to processes. Give an example of a memory management technique that
completely avoids internal fragmentation, and one that completely avoids external
fragmentation. (2p)
(b) Given a virtual memory system with 4 page frames that are initially empty, how
many page faults occur with the Least-Recently Used replacement strategy when
pages are accessed in the following order:
1, 2, 3, 4, 5, 1, 4, 3, 6, 1, 2, 5, 1.
(Justify your answer. Just guessing the right number is not acceptable.) (2p)
(c) What is thrashing in a virtual memory system? How does it occur? And what can
be done about it? (2p)
6. (4 p.) File systems
(a) What is the difference between hard links and soft (symbolic) links? (1p)
(b) Describe the file allocation method indexed allocation.
What are its strengths and weaknesses?
Describe one technique to extend indexed allocation for large files. (3p)
7. (2 p.) Disk I/O
(a) What is the purpose of disk scheduling? (1p)
(b) Name and describe one disk scheduling algorithm of your choice. (1p)
8. (6 p.) Real-Time Operating Systems
(For TDDI04 and TDDI12. Not for TDDB63 – see the next assignment instead)
Given the following set of periodic real-time tasks executing on a single processor:
Process
P1
P2
P3
Computation time per instance
10
40
20
Period (= relative deadline)
100
80
60
Assume that context switches have zero overhead.
All relative release times are zero, i.e., the first instances of P1 ,
for execution at time 0.
P2 and P3 are released
(a) Assuming that context switches have zero overhead, determine (calculation) whether
the task set is schedulable when using a rate-monotonic (RMA) scheduling approach. (2p)
(Hint: 3 (21=3 ; 1) = 0:78)
(b) Give a simple argument (calculation) to show that the task set is schedulable when
using the Earliest-Deadline First (EDF) algorithm. (1.5p)
(c) What is the purpose of the acceptance test in EDF scheduling, and how does it
work? (1.5p)
4
(d) Why is virtual memory usually not an option in hard real-time systems? (1p)
9. (6 p.) For TDDB63 only:
(a) What is a Multilevel-Feedback-Queue scheduler? Describe how it works and the
reasons for using such a scheduler in a general-purpose operating system. (2p)
(b) What is data access locality, and why is it an important property of programs that
run on a system with virtual memory? Give an example for how the programmer
can influence data access locality. (2p)
(c) Describe the principle of segmentation. Why would one prefer a segmented memory model instead of a paged memory model? (2p)
10. (3 p.) Protection and Security
(a) Suggest one (software or hardware) measure to avoid buffer-overflow vulnerabilities. (0.5p)
(b) What is a “Trojan horse” attack? (1p)
(c) Unix uses password salting in user authentification. What does that mean, and
what is its purpose? In particular, which security problem can be (partly) avoided
by salting? (1.5p)
Good luck!
5
Download