Sample Exam Questions: Licence
Sample Exam Questions: Licence
Sample Exam Questions: Licence
uk
Provided by Almae Matris Studiorum Campus
Paolo Torroni
This is a collection of past exam questions. Some of the questions are taken
from the course text books.1 For the time being, solutions are not provided.
Be aware that “Midterm” and “Final” exams only cover part of the syllabus.
A “Standard” exam instead covers all the syllabus. Exam rules and organization
of the course are summarized in the first set of slides.2
Licence
The original material in this collection is licensed under a Creative Commons
Attribution-ShareAlike 3.0 Unported License.3 This is a Free Culture licence.
You are free:
• to Share: to copy, distribute and transmit the work
• to Remix: to adapt the work
• Share Alike: If you alter, transform, or build upon this work, you may
distribute the resulting work only under the same or similar license to this
one.
8th or 9th Edition. International Student Version. Wiley 2010 (2013), and Giorgio C. But-
tazzo. Hard Real-Time Computing Systems: Predictable Scheduling Algorithms
and Applications, 3rd Edition. Springer 2011
2 https://campus.unibo.it/105196
3 http://creativecommons.org/licenses/by-sa/3.0/
Real-Time Operating Systems M
First Midterm. April 5, 2013
Part II
Please, fill in your data in the fields below. E-mail will be
used for communication of the exam results. Open questions (4 points)
O1) Illustrate the microkernel approach to OS design.
Name . . . . . . . . . . . . . . Comment on advantages and disadvantages.
O2) Describe the di↵erences among short-term, medium-
Registration No. . . . term, and long term scheduling.
O3) There are many possible CPU-scheduling algorithms.
E-mail . . . . . . . . . . . . .
How could we select one particular algorithm for a par-
ticular system? Discuss various evaluation methods.
Part I
Quizzes (2 points) Part III
int value = 5;
void *runner1(void *param);
void *runner2(void *param);
int main()
{
pthread_t tid1, tid2;
pthread_attr_t attr1, attr2;
pthread_attr_init(&attr1);
pthread_create(&tid1,&attr1,runner1,NULL);
pthread_attr_init(&attr2);
pthread_create(&tid2,&attr2,runner2,NULL);
pthread_join(tid1,NULL);
pthread_join(tid2,NULL);
return 0;
}
value += 10;
printf("B: value = %d\n", value); /* LINE B */
pthread_exit(0);
}
value += 10;
printf("C: value = %d\n", value); /* LINE C */
pthread_exit(0);
}
Real-Time Operating Systems M
First Midterm. April 5, 2013
Part II
Please, fill in your data in the fields below. E-mail will be
used for communication of the exam results. Open questions (4 points)
O1) What is the purpose of interrupts? Explain how
Name . . . . . . . . . . . . . . interrupt-driven system operation can be obtained
using dual mode operation and system calls.
Registration No. . . . O2) Explain scheduling queues.
O3) Describe the di↵erences between direct communica-
E-mail . . . . . . . . . . . . .
tion and indirect communication in message-based
systems.
Part I
Quizzes (2 points) Part III
int value = 5;
void *runner(void *param);
int main()
{
pid_t pid;
pthread_t tid;
pthread_attr_t attr;
pid = fork();
if (pid == 0) {
pthread_attr_init(&attr);
pthread_create(&tid,&attr,runner,NULL);
pthread_join(tid,NULL);
printf("B: value = %d\n", value); /* LINE B */
return 0;
}
else if (pid > 0) {
wait(NULL);
printf("C: value = %d\n", value); /* LINE C */
return 0;
}
return 0;
}
Registration No. . . .
Part III
E-mail . . . . . . . . . . . . . Exercises (3 points)
Part I E1) Consider the following snapshot of a system:
Part II
Part IV
Open questions (3 points)
Code analysis (3 points)
O1) Why do some operating systems use spinlocks as
a synchronisation mechanism only on multiprocessor The Cigarette-Smokers Problem is a well-known process
systems and not on single-processor systems? synchronisation problem that can defined as follows:
Consider a system with three smoker pro-
cesses. Each smoker continuously rolls a /* tobacco agent */
cigarette (make_cigarette()) and then smokes while(TRUE) {
wait(agentSem);
it (smoke()). But to roll a cigarette, the smoker signal(paper);
needs three resources: tobacco, paper, and signal(matches);
matches. One of the smokers has an infinite }
amount of paper, another has infinite tobacco,
and the third has infinite matches. /* paper agent */
In order to provide a given smoker with the while(TRUE) {
missing two resources, so he can roll a cigarette, wait(agentSem);
a number of other processes synchronise with one signal(tobacco);
another and with the smokers. signal(matches);
At one time, only one smoker can acquire the }
missing two resources. Smokers cannot accumu-
/* matches agent */
late resources for future use. Several smokers can while(TRUE) {
smoke at the same time, but each can smoke at wait(agentSem);
most one cigarette at a time. signal(tobacco);
signal(paper);
The following pseudo-code shows a possible solution with }
nine processes: three smokers, three pushers, and three
agents. All nine processes execute concurrently. /* tobacco pusher */
while(TRUE) {
A1) Show a possible execution that reaches LINE A. Be wait(tobacco);
sure to indicate which instructions are executed by wait(mutex);
which process before LINE A is executed. if(isPaper) {
isPaper = FALSE;
A2) Is the mutex semaphore needed? What happens signal(tobacco_and_paper);
if we remove all occurrences of wait(mutex) and }
signal(mutex) from this solution? else if(isMatches) {
isMatches = FALSE;
A3) Show how other possible synchronisation issues–in signal(tobacco_and_matches);
particular, deadlock and starvation–are solved (or }
show what synchronisation issues are unsolved, if any). else isTobacco = TRUE;
signal(mutex);
}
/* semaphores and shared global variables */
semaphore agentSem = 1, mutex = 1; /* paper pusher */
semaphore tobacco = 0, paper = 0, match = 0; while(TRUE) {
semaphore paper_and_matches = 0, wait(paper);
tobacco_and_matches = 0, wait(mutex);
tobacco_and_paper = 0; if(isTobacco) {
Boolean isPaper = FALSE, isTobacco = FALSE, isTobacco = FALSE;
isMatches = FALSE; signal(tobacco_and_paper);
}
/* smoker with tobacco */ else if(isMatches) {
while(TRUE) { isMatches = FALSE;
wait(paper_and_matches); signal(paper_and_matches);
make_cigarette(); }
signal(agentSem); else isPaper = TRUE;
smoke(); /* LINE A */ signal(mutex);
} }
E-mail . . . . . . . . . . . . .
Part III
Exercises (3 points)
Part I
E1) Consider the following snapshot of a system:
Quizzes (2 points)
Allocation Max Request
Mark each of the following statements True or False. ABCD ABCD ABCD
Explain your answer in one sentence (if you wish). P1 0012 0023 0001
P2 1354 2356 1000
T A hashed page table contains, in each entry, P3 1000 1220 0110
Q1) a pointer to a list. P4 0001 2201 2200
F
Explanation (optional): Available
1220
T Deadlock cannot occur among processes that E1.1) Is the system in deadlock?
Q2) F request (non-shareable) resources only when E1.2) Is the system in a safe state?
they have none.
E1.3) Can P2 ’s request be safely granted immediately?
Explanation (optional): E1.4) If P2 ’s request is granted immediately, does the
system enter a deadlock?
Part II
Part IV
Open questions (3 points)
Code analysis (3 points)
O1) How does the signal() operation on condition
variables associated with monitors di↵er from the The Cigarette-Smokers Problem is a well-known process
signal() operation defined for semaphores? synchronisation problem that can defined as follows:
Consider a system with three smoker pro-
cesses. Each smoker continuously rolls a /* tobacco agent */
cigarette (make_cigarette()) and then smokes while(TRUE) {
wait(agentSem);
it (smoke()). But to roll a cigarette, the smoker signal(paper);
needs three resources: tobacco, paper, and signal(matches);
matches. One of the smokers has an infinite }
amount of paper, another has infinite tobacco,
and the third has infinite matches. /* paper agent */
In order to provide a given smoker with the while(TRUE) {
missing two resources, so he can roll a cigarette, wait(agentSem);
a number of other processes synchronise with one signal(tobacco);
another and with the smokers. signal(matches);
At one time, only one smoker can acquire the }
missing two resources. Smokers cannot accumu-
/* matches agent */
late resources for future use. Several smokers can while(TRUE) {
smoke at the same time, but each can smoke at wait(agentSem);
most one cigarette at a time. signal(tobacco);
signal(paper);
The following pseudo-code shows a possible solution with }
nine processes: three smokers, three pushers, and three
agents. All nine processes execute concurrently. /* tobacco pusher */
while(TRUE) {
A1) Show a possible execution that reaches LINE A. Be wait(tobacco);
sure to indicate which instructions are executed by wait(mutex);
which process before LINE A is executed. if(isPaper) {
isPaper = FALSE;
A2) Is the mutex semaphore needed? What happens signal(tobacco_and_paper);
if we remove all occurrences of wait(mutex) and }
signal(mutex) from this solution? else if(isMatches) {
isMatches = FALSE;
A3) Show how other possible synchronisation issues–in signal(tobacco_and_matches);
particular, deadlock and starvation–are solved (or }
show what synchronisation issues are unsolved, if any). else isTobacco = TRUE;
signal(mutex);
}
/* semaphores and shared global variables */
semaphore agentSem = 1, mutex = 1; /* paper pusher */
semaphore tobacco = 0, paper = 0, match = 0; while(TRUE) {
semaphore paper_and_matches = 0, wait(paper);
tobacco_and_matches = 0, wait(mutex);
tobacco_and_paper = 0; if(isTobacco) {
Boolean isPaper = FALSE, isTobacco = FALSE, isTobacco = FALSE;
isMatches = FALSE; signal(tobacco_and_paper);
}
/* smoker with tobacco */ else if(isMatches) {
while(TRUE) { isMatches = FALSE;
wait(paper_and_matches); signal(paper_and_matches);
make_cigarette(); }
signal(agentSem); else isPaper = TRUE;
smoke(); signal(mutex);
} }
Name . . . . . . . . . . . . . .
T The working-set model is used to prevent
Registration No. . . . Q7) F thrashing while at the same time optimising
CPU utilisation.
E-mail . . . . . . . . . . . . . Explanation (optional):
Explanation (optional):
Mark each of the following statements True or False.
Explain your answer in one sentence (if you wish).
Explanation (optional):
Explanation (optional):
Part III Part IV
Exercises (6 points) Code analysis (5 points)
E1) Suppose that processes P1 , P2 , . . . , P5 arrive for execu- C1) The program below uses the Phreads API.
tion at the times indicated in Table 1. Each process
will run for the amount of time listed, and will be C1.1) What would be the output from the program at
assigned a priority ranging from 0 (highest) to 10 LINE A, LINE B, and LINE C?
(lowest). No more processes will arrive until the last C1.2) How many processes/threads would be active
process completes. by the time LINE B is executed?
int main()
Draw four Gantt charts that illustrate the execution {
of these processes using the following scheduling pid_t pid;
algorithms: pthread_t tid;
pthread_attr_t attr;
E1.1) nonpreemptive SJF;
E1.2) preemptive SJF; printf("A: value = %d\n", val); /* LINE A */
E1.3) preemptive priority (FCFS if priority is equal); pid = fork();
E1.4) RR (quantum=4).
if (pid == 0) {
In answering the questions, base all decisions on the pthread_attr_init(&attr);
information you have at the time the decision must be pthread_create(&tid,&attr,runner,NULL);
made. pthread_join(tid,NULL);
printf("B: value = %d\n", val); /* LINE B */
E2) Consider the following snapshot of a system: return 0;
}
else if (pid > 0) {
Allocation Max Request wait(NULL);
ABCD ABCD ABCD printf("C: value = %d\n", val); /* LINE C */
P1 0001 2201 2200 return 0;
P2 0012 0023 0001 }
P3 1354 2356 1000 return 0;
P4 1000 1220 0110 }
Part I
Please, fill in your data in the fields below. E-mail will be
used for communication of the exam results. Quizzes (2 points)
Mark each of the following statements True or False.
Name . . . . . . . . . . . . . . Explain your answer in one sentence (if you wish).
1 ⌧1 ⌧2 ⌧3 ⌧4 ⌧5 ⌧6
ai 0 6 4 13 0 10 Figure 4: Graphical representation of critical sections in 3.
Ci 5 4 3 4 1 1
di 20 20 19 18 20 18 Figure 5 shows phase i , period Ti = Di , worst-case
prec ⌧ 2 ! ⌧4 ⌧1 ! ⌧5 ⌧4 ! ⌧6 computation time Ci , and a description of the access
⌧ 3 ! ⌧4 ⌧5 ! ⌧6 windows to the shared resources of each task ⌧i , in
terms of start time t(Rk ) and duration i,Rk of the
critical section for each task ⌧i and each resource Rk .
Figure 1: Characteristics of the 1 task set.
3 i Ti Ci t(a) i,a t(b) i,b t(c) i,c t(d) i,d
Show the minimum lateness schedule for 1 , using a ⌧1 8 20 5 1 3
Gantt chart. Be sure to motivate your answer. ⌧2 6 30 6 1 4 3 1
⌧3 4 40 6 3 1 5 1 1 4
E2) Consider a set of periodic tasks 2 = ⌧1 , . . . , ⌧4 , to be ⌧4 2 50 3 1 1
scheduled on a single-processor machine. Figure 2 ⌧5 0 60 6 1 4 3 1
shows period Ti and worst-case computation time Ci
of each task ⌧i .
Figure 5: Characteristics of the 3 task set.
2 Ti Ci
⌧1 3 1
⌧2 4 1 E3.1) Using a Gantt chart, show the schedule under
⌧3 6 1 RM+PCP, from time 0 until completion of the
⌧4 12 2 first instance of ⌧5 . Below the Gantt chart, show
how ⌧5 ’s active priority p5 evolves.
Figure 2: Characteristics of the 2 task set.
E2.3) Is 0
2 feasible under fixed priorities?
E2.4) Is 0
2 feasible under dynamic priorities?
Part I
Please, fill in your data in the fields below. E-mail will be
used for communication of the exam results. Quizzes (2 points)
Mark each of the following statements True or False.
Name . . . . . . . . . . . . . . Explain your answer in one sentence (if you wish).
⌧i in 1 . T5 b c
1 ⌧1 ⌧2 ⌧3 ⌧4 ⌧5 ⌧6
ai 0 6 4 13 0 10
Ci 5 4 3 4 1 1 Figure 4: Graphical representation of critical sections in 3.
di 20 20 19 18 20 18
prec ⌧ 2 ! ⌧4 ⌧1 ! ⌧5 ⌧4 ! ⌧6 Figure 5 shows phase i , period Ti = Di , worst-case
⌧ 3 ! ⌧4 ⌧5 ! ⌧6 computation time Ci , and a description of the access
windows to the shared resources of each task ⌧i , in
terms of start time t(Rk ) and duration i,Rk of the
Figure 1: Characteristics of the 1 task set. critical section for each task ⌧i and each resource Rk .
Show the minimum lateness schedule for 1 , using a 3 i Ti Ci t(a) i,a t(b) i,b t(c) i,c t(d) i,d
Gantt chart. Be sure to motivate your answer. ⌧1 8 20 5 1 3
⌧2 6 30 6 1 4 3 1
E2) Consider a set of periodic tasks 2 = ⌧1 , . . . , ⌧4 , to be ⌧3 4 40 6 3 1 5 1 1 4
scheduled on a single-processor machine. Figure 2 ⌧4 2 50 3 1 1
shows period Ti and worst-case computation time Ci ⌧5 0 60 6 1 4 3 1
of each task ⌧i .
E2.3) Is 0
2 feasible under fixed priorities?
E2.4) Is 0
2 feasible under dynamic priorities?
Part I
Please, fill in your data in the fields below. E-mail will be
used for communication of the exam results. Quizzes (8 pts)
Mark each of the following statements True or False.
Name . . . . . . . . . . . . . . Explain your answer in one sentence (if you wish).
2 ⌧1 ⌧2 ⌧3 ⌧4 ⌧5 ⌧6
T The processor utilization’s least upper bound Ci 5 4 3 4 1 1
Q9) Ulub distinguishes between feasible and infeasi- di 20 20 19 18 20 18
F prec ⌧2 ! ⌧4 ⌧1 ! ⌧5 ⌧4 ! ⌧6
ble task sets.
⌧3 ! ⌧4 ⌧5 ! ⌧6
Explanation (optional):
Figure 1: Characteristics of the 2 task set.
T Priority Inversion is a phenomenon that can Show the minimum lateness schedule for 2, using a
Q10) F occur only when there are tasks sharing Gantt chart.
non-preemptible resources.
Be sure to motivate your answer.
Explanation (optional):
E3) Consider a task set 3 , composed of 5 periodic tasks
⌧1 , . . . , ⌧5 that share 4 resources a, b, c, d and execute on
a single-processor machine. 3 ’s tasks are represented
T Ceiling blocking cannot a↵ect top-priority tasks. in Figure 2. Each resource is accessed in mutual
Q11) exclusion using the Priority Ceiling Protocol (PCP).
F
Explanation (optional): T1 a
T2 a d
Exercises (13 pts) E3.1) What is the worst-case blocking time Bi for
each task ⌧i 2 3 ?
E1) Consider the following reference string: E3.2) Is 3 feasible with RM+PCP?
1, 2, 3, 4, 5, 3, 4, 1, 6, 7, 8, 7, 8, 9, 7, 8, 9, 5, 6, 5, 7. E3.3) Using a Gantt chart, show the schedule under
RM+PCP, from time 0 until completion of the
Suppose you have four page frames. How may page first instance of ⌧5 . Below the Gantt chart, show
faults occur for the LRU page replacement algorithm? how ⌧5 ’s active priority p5 evolves.
Is that the minimum possible number of page faults?
Be sure to motivate your answer.
Be sure to motivate your answer.