SlideShare une entreprise Scribd logo
1  sur  6
Télécharger pour lire hors ligne
Cairo University
                           Faculty of Computers and Information
                                         Final Exam
Department: Computer science
Course Name: Operating systems (I)                                  Date: 13th of January 2013
Course Code: CS241                                                  Duration: 2 hours
Instructor(s): Dr. Hussien Sharaf                                   Total Marks: 60

Question 1                                                                              [5 marks]
a. One of the major benefits of using threads is responsiveness. Explain how the use of threads can
    enhance responsiveness of a single program that contains a GUI and two long processes; one is
    calculating values and the other is doing disk-related operations.                     [3 marks]
b. What are the major benefits of using threads other than responsiveness?                 [2 marks]
Solution:
Chapter 4: Threads
a. Allow a program to continue running even if part of it is blocked or is performing a lengthy
    operation.
-Three threads can be used one responsible for GUI, another for the first process and another for the I/O
processing. The separation of these processes into separate threads allows the OS to switch between
them if a thread is busy with any I/O operation.
b. Major benefits of using threads other than responsiveness
    1. Resource Sharing: Threads share the memory and the resources of the process to which they
        belong by default. The benefit of sharing code and data is that it allows an application to have
        several different threads of activity within the same address space.
    2. Scalability: A single-threaded process can only run on one processor, regardless how many are
        available.
    3. Economy: Because threads share the resources of the process to which they belong, it is more
        economical to create and context-switch threads.          [optional]


Question 2                                                                              [5 marks]
a. Explain the difference between preemptive and non-preemptive scheduling.               [2 marks]
b. Can starvation occur in a non-preemptive scheduling system? Can it occur in a preemptive one?
                                                                                           [2 marks]
c. One of the methods that solve starvation is “Aging”. What is “Aging”?                  [1 marks]
Solution:
Chapter 5: CPU Scheduling
a. Difference between preemptive and non-preemptive scheduling
    1. Preemptive scheduling: The process that is loaded into the processor might be swapped out in
        favor of another process.
    2. Non-preemptive scheduling: Once the CPU has been allocated to a process, the process keeps
        the CPU until it releases the CPU either by terminating or by switching to the waiting state.
b. Yes. No.
c. Aging is a technique to avoid starvation in a scheduling system. It works by adding an aging factor to
    the priority of each process/thread.



                                               Page 1 of 6
Cairo University
                             Faculty of Computers and Information
                                           Final Exam
Question3:                                                                                           [16 marks]
Consider the following set of processes, with the estimated CPU burst given in milliseconds, and lower
priority numbers corresponding to higher CPU priority (1 is the highest):
                                                                                       Burst
The processes are assumed, to have arrived in the order P1, P2, P3, P4,   Process               Priority
                                                                                       Time
P5, all at time 0.
                                                                                      P1             10         3
                                                                                      P2             1          1
a.   Draw four Gantt charts that illustrate the execution of these processes
     using the following scheduling algorithms: non-preemptive SJF, non-          P3     2        3
     preemptive priority (a smaller priority number implies a higher              P4     1        4
     priority), RR (quantum= 1), and RR (quantum= 2).
                                                                                  P5     5        2
         [6 marks]
     For the following two sections you must use the following table.
     Do not risk losing marks:
               N-P SJF                  N-P Priority              turnaround time    turnaround time
                                                                      RR(q=1)            RR(q=2)
      turnaround Waiting turnaround Waiting turnaround Waiting turnaround Waiting
P1
P2
P3
P4
P5
b. Calculate the turnaround time of each process for each of the scheduling algorithms in part (a). [4 marks]
c. Calculate waiting time of each process for each of these scheduling algorithms in part (a). [6 marks]
Solution
Chapter 5: CPU Scheduling
a. Gantt charts
SJF
      P2 P4             P3                   P5                                 P1
    0    1      2                4                         9                                           19

non-preemptive priority
     P2          P5                                    P1                                  P3             P4
   0    1                        6                                               16                  18        19

RR(Q=1)
    P1 P2 P3 P4 P5 P1 P3 P5 P1 P5 P1 P5 P1 P5                                                             P1
   0 1   2  3  4  5  6  7  8  9 10  11 12 13 14                                                                     19

RR(Q=2)
  P1  P2         P3    P4      P5         P1        P5           P1        P5                   P1
0    2 3              5 6            8         10           12        14        15                                  19




                                                 Page 2 of 6
Cairo University
                            Faculty of Computers and Information
                                          Final Exam
            N-P SJF                  N-P Priority     turnaround time    turnaround time
                                                          RR(q=1)             RR(q=2)
      turnaround Waiting turnaround Waiting turnaround Waiting turnaround Waiting
P1         19         9           16          6         19          9      19          9
P2         1          0            1          0         2           1       3          2
P3         4          2           18         16         7           5       5          3
P4         2          1           19         18         4           3       6          5
P5         9          4            6          1         14          9      15         10
b.   Turnaround times
                        turnaround        turnaround      turnaround  turnaround
                            time             time            time         time
                            SJF           NP Priority       RR(q=1)     RR(q=2)
         P1                  19                16             19           19
         P2                   1                 1              2            3
         P3                   4                18              7            5
         P4                   2                19              4            6
         P5                   9                 6             14           15
c.   Waiting times
                        turnaround        turnaround      turnaround  turnaround
                            time             time            time         time
                            SJF           NP Priority       RR(q=1)     RR(q=2)
         P1                   9                 6              9            9
         P2                   0                 0              1            2
         P3                   2                16              5            3
         P4                   1                18              3            5
         P5                   4                 1              9           10
d.   Average waiting time for all algorithms
        SJF: 9+0+2+1+4=16               16/5 = 3.2ms
        NP Priority: 6+0+16+18+1=41      41/5 = 8.2ms
        RR(Q=1): (14-5)+(1-0)+(6-1)+(3-0)+(14-5)
        =9+1+5+3+9=16      27/5 = 5.4ms.
        RR(Q=2): (15-6)+(2-0)+(3-0)+(5-0)+(14-4)
        =9+2+3+5+10=29      29/5 = 5.8ms.

        SJF has the shortest average waiting time.

Question4:                                                                                 [6 marks]
Consider a variant of the round robin scheduling algorithm where the entries in the ready queue are
pointers to PCBs.
a. What would be the effect on turn-around time for a process that has two pointers pointing to its
    PCB in the ready queue?                                                               [2 marks]
b. Assume only two levels of priorities (with value two for the highest priority); draw a circle to show
    how the CPU time of eight (8) units is divided among P1, P2, P3, P4 and P5 with priorities [1, 1, 2, 2,
    2] respectively.                                                                      [2 marks]

                                                Page 3 of 6
Cairo University
                           Faculty of Computers and Information
                                         Final Exam
c.  How would you modify the basic RR algorithm to achieve the same effect without the use of
    duplicate pointers?                                                                   [2 marks]
Solution
Chapter 5: CPU Scheduling
a. A process that has two pointers in the ready queue pointing to its PCB; will have increased its
    priority. It gets double the time quantum in a single cycle of round robin algorithm.
b. Any process with priority 2 gets two pointers in the ready queue pointing at its PCB while a process
    with lower priority gets only one slice.

                                                        P1
                                             P3
                                                              P2


                                                  P4     P5



c. Allow a process to get double the time quantum according to its priority.
Question5:                                                                              [6 marks]
a. Assume two operations A(counter++) and B (counter--):                               [4 marks]
    A: register1 = Counter                                         B:     register2 = Counter;
        register1 = register1 + 1                                         register2 = register2 - 1
        Counter = register1                                               Counter = register2
    Show a computation sequence to illustrate how race condition may happen.
b. Why must the semaphore methods Wait() and Signal() be atomic operations?            [2 marks]
Solution:
Chapter 6: Process Synchronization
a. S0: producer execute register1 = Counter {register1 = 5}
    S1: producer execute register1 = register1 + 1 {register1 = 6}
    S2: consumer execute register2 = Counter {register2 = 5}
    S3: consumer execute register2 = register2 - 1 {register2 = 4}
    S4: producer execute counter = register1 { Counter = 6 }
    S5: consumer execute counter = register2 { Counter = 4}.
b. The semaphore methods Wait() and Signal() be atomic operations in order to prevent race
    condition.




                                              Page 4 of 6
Cairo University
                               Faculty of Computers and Information
                                             Final Exam
Question6:                                                                                   [6 marks]
Consider the following code for solving Dinning philosophers’ problem. Write code, psedocode or a flow
chart to describe what checks are needed as preconditions for changing state of Philosopher [i] to
“eating” state.

monitor DiningPhilosophers                                  void putdown (int i)
   {                                                        {
enum { THINKING; HUNGRY, EATING) state [5] ;                             state[i] = THINKING;
condition self [5];                                                     // test left and right neighbors
void pickup (int i)                                                       test((i + 4) % 5);
{                                                                         test((i + 1) % 5);
          state[i] = HUNGRY;                                        }
          test(i);                                          void test (int i) { /****missing code****/ }
if (state[i] != EATING) self [i].wait;                          main() {
}                                                                        for (int i = 0; i < 5; i++)
                                                                         state[i] = THINKING;
                                                                    }
                                                            }//End of Monitor
Solution:
Chapter 6: Process Synchronization
if ( (state[(i + 4) % 5] != EATING) &&                                      ………2 marks
                (state[i] == HUNGRY) &&                                     ………2 marks
                (state[(i + 1) % 5] != EATING) )                            ………2 marks
{
                   state[i] = EATING ;
                      self[i].signal () ;
}




                                                   Page 5 of 6
Cairo University
                            Faculty of Computers and Information
                                          Final Exam
Question7:                                                                                [8 marks]
Consider five processes P0 through P4; and three types of resources A (10 instances), B (5 instances),
and C (7 instances). Consider the following snapshot of a system:
                          Allocation        Need           Available
                          ABC               ABC            ABC
                 P0       010               743            230
                 P1       302               020
                 P2       302               600
                 P3       211               011
                 P4       002               431
Use the safety algorithm to check if this system is in a safe state and specify the safe execution sequence
that you discovered (if any).
Solution:
Chapter 7: Deadlocks
                 Allocation        Need Available
                          ABC ABC ABC
                 P1       302       020 230
                 P3       211      011 532
                 P4       002      431 743
                 P0       010 743 745
                 P2       302      600 755
                                           10 5 7
Either of P1, P3, can start: <P1, P3, P4, P0, P2>

Question8:                                                                                [8 marks]
Consider a logical address space of 32 pages of 2048 words each, mapped onto a physical memory of 8
frames.
a. How many bits are needed for addressing the total logical address?                  [2 marks]
b. How many bits are needed to indicate the page number?                               [2 marks]
c. How many bits are needed for addressing the physical address?                       [2 marks]
d. What is the effect of allowing more than one entry in a page table (each entry belongs to a process)
    to point to the same frame in physical memory?                                     [2 marks]
Solution:
Chapter 8: Main Memory
a. 32*2048=25*211 =216
Therefore 16 bits are needed for the logical address.
b. 32 =25
Therefore 5 bits are needed for the logical address.
c. 8*2048=23*211 =214
Therefore 14 bits are needed for the physical address.
d. By allowing two entries in a page table to point to the same frame in memory, processes can share
    code and data.




                                            End of Exam

                                               Page 6 of 6

Contenu connexe

Tendances

Operating Systems Process Scheduling Algorithms
Operating Systems   Process Scheduling AlgorithmsOperating Systems   Process Scheduling Algorithms
Operating Systems Process Scheduling Algorithmssathish sak
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.MOHIT DADU
 
Superscalar processor
Superscalar processorSuperscalar processor
Superscalar processornoor ul ain
 
User Interface Design- Module 2 Uid Process
User Interface Design- Module 2 Uid ProcessUser Interface Design- Module 2 Uid Process
User Interface Design- Module 2 Uid ProcessbrindaN
 
First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)nikeAthena
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentationusmankiyani1
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's typesNishant Joshi
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OSKumar Pritam
 
Real-Time Scheduling Algorithms
Real-Time Scheduling AlgorithmsReal-Time Scheduling Algorithms
Real-Time Scheduling AlgorithmsAJAL A J
 
Fundamentals of the Analysis of Algorithm Efficiency
Fundamentals of the Analysis of Algorithm EfficiencyFundamentals of the Analysis of Algorithm Efficiency
Fundamentals of the Analysis of Algorithm EfficiencySaranya Natarajan
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSKathirvel Ayyaswamy
 
Instruction pipeline: Computer Architecture
Instruction pipeline: Computer ArchitectureInstruction pipeline: Computer Architecture
Instruction pipeline: Computer ArchitectureInteX Research Lab
 
Operating System-Concepts of Process
Operating System-Concepts of ProcessOperating System-Concepts of Process
Operating System-Concepts of ProcessShipra Swati
 

Tendances (20)

Operating Systems Process Scheduling Algorithms
Operating Systems   Process Scheduling AlgorithmsOperating Systems   Process Scheduling Algorithms
Operating Systems Process Scheduling Algorithms
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
 
Priority scheduling algorithms
Priority scheduling algorithmsPriority scheduling algorithms
Priority scheduling algorithms
 
Process Scheduling
Process SchedulingProcess Scheduling
Process Scheduling
 
Superscalar processor
Superscalar processorSuperscalar processor
Superscalar processor
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
User Interface Design- Module 2 Uid Process
User Interface Design- Module 2 Uid ProcessUser Interface Design- Module 2 Uid Process
User Interface Design- Module 2 Uid Process
 
chapter 2 architecture
chapter 2 architecturechapter 2 architecture
chapter 2 architecture
 
First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentation
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's types
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Real-Time Scheduling Algorithms
Real-Time Scheduling AlgorithmsReal-Time Scheduling Algorithms
Real-Time Scheduling Algorithms
 
Parallel computing persentation
Parallel computing persentationParallel computing persentation
Parallel computing persentation
 
Parallel processing
Parallel processingParallel processing
Parallel processing
 
Fundamentals of the Analysis of Algorithm Efficiency
Fundamentals of the Analysis of Algorithm EfficiencyFundamentals of the Analysis of Algorithm Efficiency
Fundamentals of the Analysis of Algorithm Efficiency
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMS
 
Instruction pipeline: Computer Architecture
Instruction pipeline: Computer ArchitectureInstruction pipeline: Computer Architecture
Instruction pipeline: Computer Architecture
 
Operating System-Concepts of Process
Operating System-Concepts of ProcessOperating System-Concepts of Process
Operating System-Concepts of Process
 

En vedette

CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSKathirvel Ayyaswamy
 
CS9222 Advanced Operating System
CS9222 Advanced Operating SystemCS9222 Advanced Operating System
CS9222 Advanced Operating SystemKathirvel Ayyaswamy
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSKathirvel Ayyaswamy
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSKathirvel Ayyaswamy
 
Advanced Operating System Lecture Notes
Advanced Operating System Lecture NotesAdvanced Operating System Lecture Notes
Advanced Operating System Lecture NotesAnirudhan Guru
 
Advanced Operating System- Introduction
Advanced Operating System- IntroductionAdvanced Operating System- Introduction
Advanced Operating System- IntroductionDebasis Das
 
Operating system notes
Operating system notesOperating system notes
Operating system notesSANTOSH RATH
 
SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...
SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...
SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...vtunotesbysree
 

En vedette (11)

Complete Operating System notes
Complete Operating System notesComplete Operating System notes
Complete Operating System notes
 
Os Question Bank
Os Question BankOs Question Bank
Os Question Bank
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMS
 
CS9222 Advanced Operating System
CS9222 Advanced Operating SystemCS9222 Advanced Operating System
CS9222 Advanced Operating System
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMS
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMS
 
Advanced Operating System Lecture Notes
Advanced Operating System Lecture NotesAdvanced Operating System Lecture Notes
Advanced Operating System Lecture Notes
 
Advanced Operating System- Introduction
Advanced Operating System- IntroductionAdvanced Operating System- Introduction
Advanced Operating System- Introduction
 
Operating system notes pdf
Operating system notes pdfOperating system notes pdf
Operating system notes pdf
 
Operating system notes
Operating system notesOperating system notes
Operating system notes
 
SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...
SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...
SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...
 

Similaire à Final Exam OS fall 2012-2013 with answers

cpu schduling ppt.pdf
cpu schduling ppt.pdfcpu schduling ppt.pdf
cpu schduling ppt.pdfSangeethaBS4
 
AlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorit...
AlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorit...AlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorit...
AlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorit...Shanmuganathan C
 
Operating System 5
Operating System 5Operating System 5
Operating System 5tech2click
 
Cpu scheduling qusetions
Cpu scheduling qusetionsCpu scheduling qusetions
Cpu scheduling qusetionsJasonMarandi1
 
OS - CPU Scheduling
OS - CPU SchedulingOS - CPU Scheduling
OS - CPU Schedulingvinay arora
 
Cyber-physical system with machine learning (Poster)
Cyber-physical system with machine learning (Poster)Cyber-physical system with machine learning (Poster)
Cyber-physical system with machine learning (Poster)wassim bouazza
 
Operating systems-presentation
Operating systems-presentationOperating systems-presentation
Operating systems-presentationmehedi15
 
Ch6
Ch6Ch6
Ch6C.U
 
OS Process Chapter 3.pdf
OS Process Chapter 3.pdfOS Process Chapter 3.pdf
OS Process Chapter 3.pdfKp Sharma
 
Priority Scheduling
Priority Scheduling  Priority Scheduling
Priority Scheduling JawadHaider36
 

Similaire à Final Exam OS fall 2012-2013 with answers (20)

cpu schduling ppt.pdf
cpu schduling ppt.pdfcpu schduling ppt.pdf
cpu schduling ppt.pdf
 
5 Process Scheduling
5 Process Scheduling5 Process Scheduling
5 Process Scheduling
 
OSCh6
OSCh6OSCh6
OSCh6
 
OS_Ch6
OS_Ch6OS_Ch6
OS_Ch6
 
AlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorit...
AlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorit...AlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorit...
AlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorithmsAlgorit...
 
RoundRobin _ OS_LAB.pptx
RoundRobin _ OS_LAB.pptxRoundRobin _ OS_LAB.pptx
RoundRobin _ OS_LAB.pptx
 
Os module 2 ba
Os module 2 baOs module 2 ba
Os module 2 ba
 
Ch5
Ch5Ch5
Ch5
 
Operating System 5
Operating System 5Operating System 5
Operating System 5
 
Cpu scheduling qusetions
Cpu scheduling qusetionsCpu scheduling qusetions
Cpu scheduling qusetions
 
Ch5 answers
Ch5 answersCh5 answers
Ch5 answers
 
OS - CPU Scheduling
OS - CPU SchedulingOS - CPU Scheduling
OS - CPU Scheduling
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
20
20 20
20
 
Cyber-physical system with machine learning (Poster)
Cyber-physical system with machine learning (Poster)Cyber-physical system with machine learning (Poster)
Cyber-physical system with machine learning (Poster)
 
Operating systems-presentation
Operating systems-presentationOperating systems-presentation
Operating systems-presentation
 
Ch6
Ch6Ch6
Ch6
 
OS Process Chapter 3.pdf
OS Process Chapter 3.pdfOS Process Chapter 3.pdf
OS Process Chapter 3.pdf
 
Priority Scheduling
Priority Scheduling  Priority Scheduling
Priority Scheduling
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 

Plus de Arab Open University and Cairo University

Plus de Arab Open University and Cairo University (20)

Infos2014
Infos2014Infos2014
Infos2014
 
File Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswerFile Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswer
 
Model answer of compilers june spring 2013
Model answer of compilers june spring 2013Model answer of compilers june spring 2013
Model answer of compilers june spring 2013
 
Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013
 
Theory of computation Lec6
Theory of computation Lec6Theory of computation Lec6
Theory of computation Lec6
 
Lec4
Lec4Lec4
Lec4
 
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
 
Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
 
Theory of computation Lec1
Theory of computation Lec1Theory of computation Lec1
Theory of computation Lec1
 
Theory of computation Lec7 pda
Theory of computation Lec7 pdaTheory of computation Lec7 pda
Theory of computation Lec7 pda
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Setup python with eclipse
 
Cs419 lec8 top-down parsing
Cs419 lec8    top-down parsingCs419 lec8    top-down parsing
Cs419 lec8 top-down parsing
 
Cs419 lec11 bottom-up parsing
Cs419 lec11   bottom-up parsingCs419 lec11   bottom-up parsing
Cs419 lec11 bottom-up parsing
 
Cs419 lec12 semantic analyzer
Cs419 lec12  semantic analyzerCs419 lec12  semantic analyzer
Cs419 lec12 semantic analyzer
 
Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
 
Cs419 lec7 cfg
Cs419 lec7   cfgCs419 lec7   cfg
Cs419 lec7 cfg
 
Cs419 lec6 lexical analysis using nfa
Cs419 lec6   lexical analysis using nfaCs419 lec6   lexical analysis using nfa
Cs419 lec6 lexical analysis using nfa
 
Cs419 lec5 lexical analysis using dfa
Cs419 lec5   lexical analysis using dfaCs419 lec5   lexical analysis using dfa
Cs419 lec5 lexical analysis using dfa
 
Cs419 lec4 lexical analysis using re
Cs419 lec4   lexical analysis using reCs419 lec4   lexical analysis using re
Cs419 lec4 lexical analysis using re
 

Dernier

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 

Dernier (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 

Final Exam OS fall 2012-2013 with answers

  • 1. Cairo University Faculty of Computers and Information Final Exam Department: Computer science Course Name: Operating systems (I) Date: 13th of January 2013 Course Code: CS241 Duration: 2 hours Instructor(s): Dr. Hussien Sharaf Total Marks: 60 Question 1 [5 marks] a. One of the major benefits of using threads is responsiveness. Explain how the use of threads can enhance responsiveness of a single program that contains a GUI and two long processes; one is calculating values and the other is doing disk-related operations. [3 marks] b. What are the major benefits of using threads other than responsiveness? [2 marks] Solution: Chapter 4: Threads a. Allow a program to continue running even if part of it is blocked or is performing a lengthy operation. -Three threads can be used one responsible for GUI, another for the first process and another for the I/O processing. The separation of these processes into separate threads allows the OS to switch between them if a thread is busy with any I/O operation. b. Major benefits of using threads other than responsiveness 1. Resource Sharing: Threads share the memory and the resources of the process to which they belong by default. The benefit of sharing code and data is that it allows an application to have several different threads of activity within the same address space. 2. Scalability: A single-threaded process can only run on one processor, regardless how many are available. 3. Economy: Because threads share the resources of the process to which they belong, it is more economical to create and context-switch threads. [optional] Question 2 [5 marks] a. Explain the difference between preemptive and non-preemptive scheduling. [2 marks] b. Can starvation occur in a non-preemptive scheduling system? Can it occur in a preemptive one? [2 marks] c. One of the methods that solve starvation is “Aging”. What is “Aging”? [1 marks] Solution: Chapter 5: CPU Scheduling a. Difference between preemptive and non-preemptive scheduling 1. Preemptive scheduling: The process that is loaded into the processor might be swapped out in favor of another process. 2. Non-preemptive scheduling: Once the CPU has been allocated to a process, the process keeps the CPU until it releases the CPU either by terminating or by switching to the waiting state. b. Yes. No. c. Aging is a technique to avoid starvation in a scheduling system. It works by adding an aging factor to the priority of each process/thread. Page 1 of 6
  • 2. Cairo University Faculty of Computers and Information Final Exam Question3: [16 marks] Consider the following set of processes, with the estimated CPU burst given in milliseconds, and lower priority numbers corresponding to higher CPU priority (1 is the highest): Burst The processes are assumed, to have arrived in the order P1, P2, P3, P4, Process Priority Time P5, all at time 0. P1 10 3 P2 1 1 a. Draw four Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: non-preemptive SJF, non- P3 2 3 preemptive priority (a smaller priority number implies a higher P4 1 4 priority), RR (quantum= 1), and RR (quantum= 2). P5 5 2 [6 marks] For the following two sections you must use the following table. Do not risk losing marks: N-P SJF N-P Priority turnaround time turnaround time RR(q=1) RR(q=2) turnaround Waiting turnaround Waiting turnaround Waiting turnaround Waiting P1 P2 P3 P4 P5 b. Calculate the turnaround time of each process for each of the scheduling algorithms in part (a). [4 marks] c. Calculate waiting time of each process for each of these scheduling algorithms in part (a). [6 marks] Solution Chapter 5: CPU Scheduling a. Gantt charts SJF P2 P4 P3 P5 P1 0 1 2 4 9 19 non-preemptive priority P2 P5 P1 P3 P4 0 1 6 16 18 19 RR(Q=1) P1 P2 P3 P4 P5 P1 P3 P5 P1 P5 P1 P5 P1 P5 P1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 19 RR(Q=2) P1 P2 P3 P4 P5 P1 P5 P1 P5 P1 0 2 3 5 6 8 10 12 14 15 19 Page 2 of 6
  • 3. Cairo University Faculty of Computers and Information Final Exam N-P SJF N-P Priority turnaround time turnaround time RR(q=1) RR(q=2) turnaround Waiting turnaround Waiting turnaround Waiting turnaround Waiting P1 19 9 16 6 19 9 19 9 P2 1 0 1 0 2 1 3 2 P3 4 2 18 16 7 5 5 3 P4 2 1 19 18 4 3 6 5 P5 9 4 6 1 14 9 15 10 b. Turnaround times turnaround turnaround turnaround turnaround time time time time SJF NP Priority RR(q=1) RR(q=2) P1 19 16 19 19 P2 1 1 2 3 P3 4 18 7 5 P4 2 19 4 6 P5 9 6 14 15 c. Waiting times turnaround turnaround turnaround turnaround time time time time SJF NP Priority RR(q=1) RR(q=2) P1 9 6 9 9 P2 0 0 1 2 P3 2 16 5 3 P4 1 18 3 5 P5 4 1 9 10 d. Average waiting time for all algorithms SJF: 9+0+2+1+4=16 16/5 = 3.2ms NP Priority: 6+0+16+18+1=41 41/5 = 8.2ms RR(Q=1): (14-5)+(1-0)+(6-1)+(3-0)+(14-5) =9+1+5+3+9=16 27/5 = 5.4ms. RR(Q=2): (15-6)+(2-0)+(3-0)+(5-0)+(14-4) =9+2+3+5+10=29 29/5 = 5.8ms. SJF has the shortest average waiting time. Question4: [6 marks] Consider a variant of the round robin scheduling algorithm where the entries in the ready queue are pointers to PCBs. a. What would be the effect on turn-around time for a process that has two pointers pointing to its PCB in the ready queue? [2 marks] b. Assume only two levels of priorities (with value two for the highest priority); draw a circle to show how the CPU time of eight (8) units is divided among P1, P2, P3, P4 and P5 with priorities [1, 1, 2, 2, 2] respectively. [2 marks] Page 3 of 6
  • 4. Cairo University Faculty of Computers and Information Final Exam c. How would you modify the basic RR algorithm to achieve the same effect without the use of duplicate pointers? [2 marks] Solution Chapter 5: CPU Scheduling a. A process that has two pointers in the ready queue pointing to its PCB; will have increased its priority. It gets double the time quantum in a single cycle of round robin algorithm. b. Any process with priority 2 gets two pointers in the ready queue pointing at its PCB while a process with lower priority gets only one slice. P1 P3 P2 P4 P5 c. Allow a process to get double the time quantum according to its priority. Question5: [6 marks] a. Assume two operations A(counter++) and B (counter--): [4 marks] A: register1 = Counter B: register2 = Counter; register1 = register1 + 1 register2 = register2 - 1 Counter = register1 Counter = register2 Show a computation sequence to illustrate how race condition may happen. b. Why must the semaphore methods Wait() and Signal() be atomic operations? [2 marks] Solution: Chapter 6: Process Synchronization a. S0: producer execute register1 = Counter {register1 = 5} S1: producer execute register1 = register1 + 1 {register1 = 6} S2: consumer execute register2 = Counter {register2 = 5} S3: consumer execute register2 = register2 - 1 {register2 = 4} S4: producer execute counter = register1 { Counter = 6 } S5: consumer execute counter = register2 { Counter = 4}. b. The semaphore methods Wait() and Signal() be atomic operations in order to prevent race condition. Page 4 of 6
  • 5. Cairo University Faculty of Computers and Information Final Exam Question6: [6 marks] Consider the following code for solving Dinning philosophers’ problem. Write code, psedocode or a flow chart to describe what checks are needed as preconditions for changing state of Philosopher [i] to “eating” state. monitor DiningPhilosophers void putdown (int i) { { enum { THINKING; HUNGRY, EATING) state [5] ; state[i] = THINKING; condition self [5]; // test left and right neighbors void pickup (int i) test((i + 4) % 5); { test((i + 1) % 5); state[i] = HUNGRY; } test(i); void test (int i) { /****missing code****/ } if (state[i] != EATING) self [i].wait; main() { } for (int i = 0; i < 5; i++) state[i] = THINKING; } }//End of Monitor Solution: Chapter 6: Process Synchronization if ( (state[(i + 4) % 5] != EATING) && ………2 marks (state[i] == HUNGRY) && ………2 marks (state[(i + 1) % 5] != EATING) ) ………2 marks { state[i] = EATING ; self[i].signal () ; } Page 5 of 6
  • 6. Cairo University Faculty of Computers and Information Final Exam Question7: [8 marks] Consider five processes P0 through P4; and three types of resources A (10 instances), B (5 instances), and C (7 instances). Consider the following snapshot of a system: Allocation Need Available ABC ABC ABC P0 010 743 230 P1 302 020 P2 302 600 P3 211 011 P4 002 431 Use the safety algorithm to check if this system is in a safe state and specify the safe execution sequence that you discovered (if any). Solution: Chapter 7: Deadlocks Allocation Need Available ABC ABC ABC P1 302 020 230 P3 211 011 532 P4 002 431 743 P0 010 743 745 P2 302 600 755 10 5 7 Either of P1, P3, can start: <P1, P3, P4, P0, P2> Question8: [8 marks] Consider a logical address space of 32 pages of 2048 words each, mapped onto a physical memory of 8 frames. a. How many bits are needed for addressing the total logical address? [2 marks] b. How many bits are needed to indicate the page number? [2 marks] c. How many bits are needed for addressing the physical address? [2 marks] d. What is the effect of allowing more than one entry in a page table (each entry belongs to a process) to point to the same frame in physical memory? [2 marks] Solution: Chapter 8: Main Memory a. 32*2048=25*211 =216 Therefore 16 bits are needed for the logical address. b. 32 =25 Therefore 5 bits are needed for the logical address. c. 8*2048=23*211 =214 Therefore 14 bits are needed for the physical address. d. By allowing two entries in a page table to point to the same frame in memory, processes can share code and data. End of Exam Page 6 of 6