SlideShare une entreprise Scribd logo
1  sur  7
Télécharger pour lire hors ligne
Name:____________________________________ ID:___________________
1
Addis Ababa University
Institute of Technology
Information Technology and Scientific Computing
2013, First Semester Lisanu Tebikew
Sample Mid-Term Exam
Nov 30, 2013
ITSC 4931 Operating Systems
Your Name:
ID Number:
1. This is a closed book exam. You may not use any reference materials
during the exam; if you have any notes on you please put them away.
2. You have 3 hours to complete as much of the exam as possible.
3. Answer all questions directly on the space provided bellow each
question. The weight of each question is indicated at the beginning of
each question in parentheses.
4. Make your answers as concise as possible. You will receive partial
credit for partially correct answers.
5. Write your name on this cover sheet AND at the top of each page of
this booklet, since some pages might get detached.
6. If there is something about the questions that you believe is open to
interpretation, please ask the instructor about it!
Don’t Begin The Exam Until You Are Told To Do So!
Good Luck!!
Name:____________________________________ ID:___________________
2
Part I: Threads
1. (2 points) What are the main functions of an operating system?
2. (4 points) How are “user mode” and “kernel mode” different? How are
they important to Operating systems? Name three ways in which the
processor can transition from user mode to kernel mode. Can the user
execute arbitrary code after transitioning?
3. Give a brief definition for each of the following terms as they apply to
this course.
a. (2 Points) Register
b. (2 points) Stack
c. (2 points) System call
d. (2 points) program counter
4. (4 points) What is an interrupt, briefly describe the steps that the
computer system performs to handle an interrupt.
5.
a. (2 points) What is Context switching?
b. (2 points) Describe the General steps needed to perform Context
switching?
6. (2 points) Assume that you wanted to write a C program which will
write zeroes throughout the address space of your Linux computer’s shell
program (i.e., bash). To your sadness you discover that the operating
system has placed a hardware barrier in your path. How does the computer
hardware prevent the program you are going to write from accessing
memory that doesn’t belong to it?
Name:____________________________________ ID:___________________
3
Running
New Ready
Waiting
Terminated
7. (6 points) Here are nodes for three states a process can be in. Draw
directed arcs (i.e., arrows) between the nodes to indicate all transitions a
process can use (For example, draw an arc from Ready to New if a process
can go from being Ready to being Newly created). Label each arc with a 1-
word summary term (how that transition occurs) and then, below the figure,
provide a brief explanation of why such a transition happens (1 or 2
sentences should suffice) of what you meant by each summary term.
8. (4 points) Consider the following program? What would its output be?
(Hint: the echo program displays whatever is given to it to the screen)
int main(int argc, char *argv[]) {
int child_pid = fork();
if (child_pid == 0) {
printf(“Child’s id is %dn”, getpid());
execl(“/bin/echo”,”echo”,”Hello there”,NULL);
return 0;
}
else {
printf(“My child is %dn”, child_pid);
return 0;
}
}
Name:____________________________________ ID:___________________
4
9. (2 point) Suggest one program that can use multiple threads to do many
things at once?
10. (8 points) Consider a multithreaded program (a process having many
threads).
For the components of the program listed in the following table put an X
mark under the Private column if that resource is private to each thread and
Put an X mark under the Shared column if that resource is shared between
threads of the same process.
Component Private Shared
Program Counter
Register values
Program’s Code
Program’s Data (Global Variables)
Program’s Heap
Program’s Stack
Operating System resources such as
files, network connections
Program’s State (whether it is Ready,
Blocked, Waiting)
Part II: Synchronization
11. Suppose a thread is running in a critical section of code, meaning that
it has acquired all the locks through proper arbitration. Can it get context
switched? Why or why not?
12. Show how to implement a Semaphore using a Lock and Condition
Variable). Make sure to implement both methods, P(), and V().
Name:____________________________________ ID:___________________
5
13. (6 points) Observing that building the “Great Ethiopian Dam” needs
everybody’s contribution, a famous bank called EthioBucks has launched
a new system called Bootex. Bootex’s server allows the bank’s customers
to donate 10 Birr to the Great Ethiopian Dam by clicking a button which
says DONATE on Bootex’s web site.
Every such button click Bootex creates another thread which executes a
function called donate. The donate function accepts the customer’s
account number, decrements 10 birr from the customer’s balance, and
updates the customer’s balance.
The donate function is coded as follows.
void donate (int accountNumber){
//Get the sender’s balance by calling another function called
//get_balance.
int balance = get_balance(accountNumber);
//decrement 10 birr from the sender’s account balance
balance = balance – 10;
//update the balance of the phone number
save_balance(accountNumber, balance);
}
Abebe and Kebede, who use the same bank account, are working on
different computers and they simultaneously clicked on the DONATE button.
But when they check their balance they find out that only 10 birr is
deducted. But since the DONATE button was clicked twice; 2 * 10 = 20 birr
should have been deducted.
i. Give a simple scenario involving two threads, T1 and T2( serving
Abebe and Kebede respectively), with interleaved execution that
would result in only 10 Birr being deducted from their account.
Name:____________________________________ ID:___________________
6
ii. (6 points) Describe of how Mutexes can be used to protect critical
sections, and solve problems like the one stated in question 4.1.
14. What is a monitor?
15. What is the difference between Mesa and Hoare scheduling for
monitors?
16. Consider show the Readers-Writers example given in class (Not
Included here on the sample exam due to space constraints, but on the
real exam it is). It used two condition variables, one for waiting readers
and one for waiting writers. Suppose that all of the following requests
arrive in very short order (while R1 and R2 are still executing):
Incoming stream: R1 R2 W1W2R3 R4 R5 W3 R6W4 W5 R7 R8W6 R9
In what order would the above code process the above requests?
Part V: InterProcess Communication and Deadlock
17. Name two ways in which processes on the same processor can
communicate with one another. And explain how each one of them work.
18. What is the difference between a deadlock and a starvation?
19. Does a cyclic dependency always lead to deadlock? Why or why not?
20. List the conditions for deadlock.
21. What are three methods of dealing with the possibility of deadlock?
Explain each method and its consequences to programmer of
applications.
22. The Banker’s algorithm is said to keep the system in a “safe” state.
Describe what a “safe” state is and explain how the Banker’s algorithm
keeps the system in a safe state. Keep your answer short.
Part IV: Scheduling
23. Provide a brief explanation of what are preemptive and non-
preemptive scheduling policies.
24. Name at least three ways in which context-switching can happen in a
nonpreemptive scheduler.
Name:____________________________________ ID:___________________
7
25. Describe how First Come First Served (FCFS), Round Robin (RR),
Shortest Job First (SJF), Shortest Remaining Time First (SRTF) and
Priority Scheduling algorithms work?
26. Why is SJF or SRTF scheduling difficult to implement in a real OS?
27. Here is a table of processes, their arrival time and their associated
running times.
Pricess ID Arrival Time Expected CPU
Running Time
Process ID 0 4
Process 1 1 5
Process 2 3 4
Process 3 4 1
Process 4 7 2
Show the scheduling order for these processes under First-In-First- Out
(FIFO), Shortest-Job First (SJF), and Round-Robin (RR) with a quantum = 1
time unit. Assume that the context switch overhead is 0 and new processes
are added to the head of the queue except for FIFO.

Contenu connexe

Tendances

Operating system structures
Operating system structuresOperating system structures
Operating system structures
Mohd Arif
 
Processes in unix
Processes in unixProcesses in unix
Processes in unix
miau_max
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
Mahesh Bhalerao
 
Context Switching
Context SwitchingContext Switching
Context Switching
franksvalli
 

Tendances (20)

Unit II - 1 - Operating System Process
Unit II - 1 - Operating System ProcessUnit II - 1 - Operating System Process
Unit II - 1 - Operating System Process
 
Operating system structures
Operating system structuresOperating system structures
Operating system structures
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Modes of transfer
Modes of transferModes of transfer
Modes of transfer
 
Complete Operating System notes
Complete Operating System notesComplete Operating System notes
Complete Operating System notes
 
Processes in unix
Processes in unixProcesses in unix
Processes in unix
 
Protection and security
Protection and securityProtection and security
Protection and security
 
Instruction pipeline: Computer Architecture
Instruction pipeline: Computer ArchitectureInstruction pipeline: Computer Architecture
Instruction pipeline: Computer Architecture
 
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Modes Of Transfer in Input/Output Organization
Modes Of Transfer in Input/Output OrganizationModes Of Transfer in Input/Output Organization
Modes Of Transfer in Input/Output Organization
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
evolution of operating system
evolution of operating systemevolution of operating system
evolution of operating system
 
Swapping | Computer Science
Swapping | Computer ScienceSwapping | Computer Science
Swapping | Computer Science
 
Introduction to Operating Systems
Introduction to Operating SystemsIntroduction to Operating Systems
Introduction to Operating Systems
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Prevention
 
Context Switching
Context SwitchingContext Switching
Context Switching
 
Deadlock
DeadlockDeadlock
Deadlock
 
Dead Lock
Dead LockDead Lock
Dead Lock
 
Computer architecture pipelining
Computer architecture pipeliningComputer architecture pipelining
Computer architecture pipelining
 

En vedette

Danske kreds 0115WEB
Danske kreds 0115WEBDanske kreds 0115WEB
Danske kreds 0115WEB
Rasmus Hach
 
Leung-LokYin-6155-P-Futurewise Report
Leung-LokYin-6155-P-Futurewise ReportLeung-LokYin-6155-P-Futurewise Report
Leung-LokYin-6155-P-Futurewise Report
lok yin leung
 
Approval Of Mr.Haseebuddin FGPSP-SA-AYC-T-0975
Approval Of Mr.Haseebuddin FGPSP-SA-AYC-T-0975Approval Of Mr.Haseebuddin FGPSP-SA-AYC-T-0975
Approval Of Mr.Haseebuddin FGPSP-SA-AYC-T-0975
haseeb uddin
 
SurveyProject_Exclusive Relationships
SurveyProject_Exclusive RelationshipsSurveyProject_Exclusive Relationships
SurveyProject_Exclusive Relationships
Sherri Wielgos
 
C. L. Brewer Ascend resume
C. L. Brewer Ascend resumeC. L. Brewer Ascend resume
C. L. Brewer Ascend resume
Candice Ballard
 

En vedette (15)

Health care prevention emiley reed
Health care prevention emiley reedHealth care prevention emiley reed
Health care prevention emiley reed
 
Maker faire 期末報告
Maker faire 期末報告Maker faire 期末報告
Maker faire 期末報告
 
Tenses
TensesTenses
Tenses
 
Danske kreds 0115WEB
Danske kreds 0115WEBDanske kreds 0115WEB
Danske kreds 0115WEB
 
Train sense
Train senseTrain sense
Train sense
 
Leung-LokYin-6155-P-Futurewise Report
Leung-LokYin-6155-P-Futurewise ReportLeung-LokYin-6155-P-Futurewise Report
Leung-LokYin-6155-P-Futurewise Report
 
Sreekanth cv 12-7-15
Sreekanth cv 12-7-15Sreekanth cv 12-7-15
Sreekanth cv 12-7-15
 
Approval Of Mr.Haseebuddin FGPSP-SA-AYC-T-0975
Approval Of Mr.Haseebuddin FGPSP-SA-AYC-T-0975Approval Of Mr.Haseebuddin FGPSP-SA-AYC-T-0975
Approval Of Mr.Haseebuddin FGPSP-SA-AYC-T-0975
 
Questionnaire Results
Questionnaire ResultsQuestionnaire Results
Questionnaire Results
 
Actividad 3.2
Actividad 3.2Actividad 3.2
Actividad 3.2
 
Ensayo de Ingeneria Electrica
Ensayo de Ingeneria ElectricaEnsayo de Ingeneria Electrica
Ensayo de Ingeneria Electrica
 
Variety of clones santa barbara
Variety of clones santa barbaraVariety of clones santa barbara
Variety of clones santa barbara
 
SurveyProject_Exclusive Relationships
SurveyProject_Exclusive RelationshipsSurveyProject_Exclusive Relationships
SurveyProject_Exclusive Relationships
 
C. L. Brewer Ascend resume
C. L. Brewer Ascend resumeC. L. Brewer Ascend resume
C. L. Brewer Ascend resume
 
store_design
store_designstore_design
store_design
 

Similaire à Os sample mid exam

Due 24 August (Friday, 1159 p.m. EDT)Use Module 1 and Book Ch.docx
Due 24 August (Friday, 1159 p.m. EDT)Use Module 1 and Book Ch.docxDue 24 August (Friday, 1159 p.m. EDT)Use Module 1 and Book Ch.docx
Due 24 August (Friday, 1159 p.m. EDT)Use Module 1 and Book Ch.docx
jacksnathalie
 
CIS 512 discussion post responses.CPUs and Programming Pleas.docx
CIS 512 discussion post responses.CPUs and Programming Pleas.docxCIS 512 discussion post responses.CPUs and Programming Pleas.docx
CIS 512 discussion post responses.CPUs and Programming Pleas.docx
mccormicknadine86
 
MC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall sessionMC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall session
Narinder Kumar
 
Test03 solution
Test03 solutionTest03 solution
Test03 solution
fmbuthia
 

Similaire à Os sample mid exam (20)

Bsc it winter 2013 2nd sem
Bsc it  winter 2013 2nd semBsc it  winter 2013 2nd sem
Bsc it winter 2013 2nd sem
 
parallel Questions & answers
parallel Questions & answersparallel Questions & answers
parallel Questions & answers
 
Knowledge representation and reasoning
Knowledge representation and reasoningKnowledge representation and reasoning
Knowledge representation and reasoning
 
Mi0034 database management system
Mi0034   database management systemMi0034   database management system
Mi0034 database management system
 
Pune University MCA [Management] 2020-Sample Questions
Pune University MCA [Management] 2020-Sample QuestionsPune University MCA [Management] 2020-Sample Questions
Pune University MCA [Management] 2020-Sample Questions
 
Due 24 August (Friday, 1159 p.m. EDT)Use Module 1 and Book Ch.docx
Due 24 August (Friday, 1159 p.m. EDT)Use Module 1 and Book Ch.docxDue 24 August (Friday, 1159 p.m. EDT)Use Module 1 and Book Ch.docx
Due 24 August (Friday, 1159 p.m. EDT)Use Module 1 and Book Ch.docx
 
CIS 512 discussion post responses.CPUs and Programming Pleas.docx
CIS 512 discussion post responses.CPUs and Programming Pleas.docxCIS 512 discussion post responses.CPUs and Programming Pleas.docx
CIS 512 discussion post responses.CPUs and Programming Pleas.docx
 
Introduction.pptx
Introduction.pptxIntroduction.pptx
Introduction.pptx
 
Bca winter 2013 2nd sem
Bca winter 2013 2nd semBca winter 2013 2nd sem
Bca winter 2013 2nd sem
 
MC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall sessionMC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall session
 
9th_Computer Full Exercise
9th_Computer Full Exercise 9th_Computer Full Exercise
9th_Computer Full Exercise
 
Test03 solution
Test03 solutionTest03 solution
Test03 solution
 
midterm_fa07.pdf
midterm_fa07.pdfmidterm_fa07.pdf
midterm_fa07.pdf
 
Python for Machine Learning
Python for Machine LearningPython for Machine Learning
Python for Machine Learning
 
Higher Homework
Higher HomeworkHigher Homework
Higher Homework
 
SP Solutions -Adi.pdf
SP Solutions -Adi.pdfSP Solutions -Adi.pdf
SP Solutions -Adi.pdf
 
SP_Solutions_-Adi.pdf
SP_Solutions_-Adi.pdfSP_Solutions_-Adi.pdf
SP_Solutions_-Adi.pdf
 
SP_Solutions_-Adi.pdf
SP_Solutions_-Adi.pdfSP_Solutions_-Adi.pdf
SP_Solutions_-Adi.pdf
 
Cmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.comCmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.com
 
Cmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.comCmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.com
 

Dernier

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Dernier (20)

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 

Os sample mid exam

  • 1. Name:____________________________________ ID:___________________ 1 Addis Ababa University Institute of Technology Information Technology and Scientific Computing 2013, First Semester Lisanu Tebikew Sample Mid-Term Exam Nov 30, 2013 ITSC 4931 Operating Systems Your Name: ID Number: 1. This is a closed book exam. You may not use any reference materials during the exam; if you have any notes on you please put them away. 2. You have 3 hours to complete as much of the exam as possible. 3. Answer all questions directly on the space provided bellow each question. The weight of each question is indicated at the beginning of each question in parentheses. 4. Make your answers as concise as possible. You will receive partial credit for partially correct answers. 5. Write your name on this cover sheet AND at the top of each page of this booklet, since some pages might get detached. 6. If there is something about the questions that you believe is open to interpretation, please ask the instructor about it! Don’t Begin The Exam Until You Are Told To Do So! Good Luck!!
  • 2. Name:____________________________________ ID:___________________ 2 Part I: Threads 1. (2 points) What are the main functions of an operating system? 2. (4 points) How are “user mode” and “kernel mode” different? How are they important to Operating systems? Name three ways in which the processor can transition from user mode to kernel mode. Can the user execute arbitrary code after transitioning? 3. Give a brief definition for each of the following terms as they apply to this course. a. (2 Points) Register b. (2 points) Stack c. (2 points) System call d. (2 points) program counter 4. (4 points) What is an interrupt, briefly describe the steps that the computer system performs to handle an interrupt. 5. a. (2 points) What is Context switching? b. (2 points) Describe the General steps needed to perform Context switching? 6. (2 points) Assume that you wanted to write a C program which will write zeroes throughout the address space of your Linux computer’s shell program (i.e., bash). To your sadness you discover that the operating system has placed a hardware barrier in your path. How does the computer hardware prevent the program you are going to write from accessing memory that doesn’t belong to it?
  • 3. Name:____________________________________ ID:___________________ 3 Running New Ready Waiting Terminated 7. (6 points) Here are nodes for three states a process can be in. Draw directed arcs (i.e., arrows) between the nodes to indicate all transitions a process can use (For example, draw an arc from Ready to New if a process can go from being Ready to being Newly created). Label each arc with a 1- word summary term (how that transition occurs) and then, below the figure, provide a brief explanation of why such a transition happens (1 or 2 sentences should suffice) of what you meant by each summary term. 8. (4 points) Consider the following program? What would its output be? (Hint: the echo program displays whatever is given to it to the screen) int main(int argc, char *argv[]) { int child_pid = fork(); if (child_pid == 0) { printf(“Child’s id is %dn”, getpid()); execl(“/bin/echo”,”echo”,”Hello there”,NULL); return 0; } else { printf(“My child is %dn”, child_pid); return 0; } }
  • 4. Name:____________________________________ ID:___________________ 4 9. (2 point) Suggest one program that can use multiple threads to do many things at once? 10. (8 points) Consider a multithreaded program (a process having many threads). For the components of the program listed in the following table put an X mark under the Private column if that resource is private to each thread and Put an X mark under the Shared column if that resource is shared between threads of the same process. Component Private Shared Program Counter Register values Program’s Code Program’s Data (Global Variables) Program’s Heap Program’s Stack Operating System resources such as files, network connections Program’s State (whether it is Ready, Blocked, Waiting) Part II: Synchronization 11. Suppose a thread is running in a critical section of code, meaning that it has acquired all the locks through proper arbitration. Can it get context switched? Why or why not? 12. Show how to implement a Semaphore using a Lock and Condition Variable). Make sure to implement both methods, P(), and V().
  • 5. Name:____________________________________ ID:___________________ 5 13. (6 points) Observing that building the “Great Ethiopian Dam” needs everybody’s contribution, a famous bank called EthioBucks has launched a new system called Bootex. Bootex’s server allows the bank’s customers to donate 10 Birr to the Great Ethiopian Dam by clicking a button which says DONATE on Bootex’s web site. Every such button click Bootex creates another thread which executes a function called donate. The donate function accepts the customer’s account number, decrements 10 birr from the customer’s balance, and updates the customer’s balance. The donate function is coded as follows. void donate (int accountNumber){ //Get the sender’s balance by calling another function called //get_balance. int balance = get_balance(accountNumber); //decrement 10 birr from the sender’s account balance balance = balance – 10; //update the balance of the phone number save_balance(accountNumber, balance); } Abebe and Kebede, who use the same bank account, are working on different computers and they simultaneously clicked on the DONATE button. But when they check their balance they find out that only 10 birr is deducted. But since the DONATE button was clicked twice; 2 * 10 = 20 birr should have been deducted. i. Give a simple scenario involving two threads, T1 and T2( serving Abebe and Kebede respectively), with interleaved execution that would result in only 10 Birr being deducted from their account.
  • 6. Name:____________________________________ ID:___________________ 6 ii. (6 points) Describe of how Mutexes can be used to protect critical sections, and solve problems like the one stated in question 4.1. 14. What is a monitor? 15. What is the difference between Mesa and Hoare scheduling for monitors? 16. Consider show the Readers-Writers example given in class (Not Included here on the sample exam due to space constraints, but on the real exam it is). It used two condition variables, one for waiting readers and one for waiting writers. Suppose that all of the following requests arrive in very short order (while R1 and R2 are still executing): Incoming stream: R1 R2 W1W2R3 R4 R5 W3 R6W4 W5 R7 R8W6 R9 In what order would the above code process the above requests? Part V: InterProcess Communication and Deadlock 17. Name two ways in which processes on the same processor can communicate with one another. And explain how each one of them work. 18. What is the difference between a deadlock and a starvation? 19. Does a cyclic dependency always lead to deadlock? Why or why not? 20. List the conditions for deadlock. 21. What are three methods of dealing with the possibility of deadlock? Explain each method and its consequences to programmer of applications. 22. The Banker’s algorithm is said to keep the system in a “safe” state. Describe what a “safe” state is and explain how the Banker’s algorithm keeps the system in a safe state. Keep your answer short. Part IV: Scheduling 23. Provide a brief explanation of what are preemptive and non- preemptive scheduling policies. 24. Name at least three ways in which context-switching can happen in a nonpreemptive scheduler.
  • 7. Name:____________________________________ ID:___________________ 7 25. Describe how First Come First Served (FCFS), Round Robin (RR), Shortest Job First (SJF), Shortest Remaining Time First (SRTF) and Priority Scheduling algorithms work? 26. Why is SJF or SRTF scheduling difficult to implement in a real OS? 27. Here is a table of processes, their arrival time and their associated running times. Pricess ID Arrival Time Expected CPU Running Time Process ID 0 4 Process 1 1 5 Process 2 3 4 Process 3 4 1 Process 4 7 2 Show the scheduling order for these processes under First-In-First- Out (FIFO), Shortest-Job First (SJF), and Round-Robin (RR) with a quantum = 1 time unit. Assume that the context switch overhead is 0 and new processes are added to the head of the queue except for FIFO.