SlideShare a Scribd company logo
1 of 6
Download to read offline
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

More Related Content

What's hot

First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)nikeAthena
 
Remote Procedure Call in Distributed System
Remote Procedure Call in Distributed SystemRemote Procedure Call in Distributed System
Remote Procedure Call in Distributed SystemPoojaBele1
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemMadhu Bala
 
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
 
Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Ra'Fat Al-Msie'deen
 
Distributed operating system(os)
Distributed operating system(os)Distributed operating system(os)
Distributed operating system(os)Dinesh Modak
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor schedulingShashank Kapoor
 
Distance Vector & Link state Routing Algorithm
Distance Vector & Link state Routing AlgorithmDistance Vector & Link state Routing Algorithm
Distance Vector & Link state Routing AlgorithmMOHIT AGARWAL
 
Lecture 1 introduction to parallel and distributed computing
Lecture 1   introduction to parallel and distributed computingLecture 1   introduction to parallel and distributed computing
Lecture 1 introduction to parallel and distributed computingVajira Thambawita
 
Synchronization in distributed computing
Synchronization in distributed computingSynchronization in distributed computing
Synchronization in distributed computingSVijaylakshmi
 
Communication costs in parallel machines
Communication costs in parallel machinesCommunication costs in parallel machines
Communication costs in parallel machinesSyed Zaid Irshad
 
Introduction to System Calls
Introduction to System CallsIntroduction to System Calls
Introduction to System CallsVandana Salve
 

What's hot (20)

Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)
 
Lecture 3 threads
Lecture 3   threadsLecture 3   threads
Lecture 3 threads
 
Remote Procedure Call in Distributed System
Remote Procedure Call in Distributed SystemRemote Procedure Call in Distributed System
Remote Procedure Call in Distributed System
 
Threads .ppt
Threads .pptThreads .ppt
Threads .ppt
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
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...
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"
 
Distributed operating system(os)
Distributed operating system(os)Distributed operating system(os)
Distributed operating system(os)
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor scheduling
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Open mp directives
Open mp directivesOpen mp directives
Open mp directives
 
Distance Vector & Link state Routing Algorithm
Distance Vector & Link state Routing AlgorithmDistance Vector & Link state Routing Algorithm
Distance Vector & Link state Routing Algorithm
 
Lecture 1 introduction to parallel and distributed computing
Lecture 1   introduction to parallel and distributed computingLecture 1   introduction to parallel and distributed computing
Lecture 1 introduction to parallel and distributed computing
 
Synchronization in distributed computing
Synchronization in distributed computingSynchronization in distributed computing
Synchronization in distributed computing
 
Communication costs in parallel machines
Communication costs in parallel machinesCommunication costs in parallel machines
Communication costs in parallel machines
 
Introduction to System Calls
Introduction to System CallsIntroduction to System Calls
Introduction to System Calls
 
Semaphores
SemaphoresSemaphores
Semaphores
 

Viewers also liked

Viewers also liked (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
 
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
 

Similar to 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
 

Similar to Final Exam OS fall 2012-2013 with answers (20)

cpu schduling ppt.pdf
cpu schduling ppt.pdfcpu schduling ppt.pdf
cpu schduling ppt.pdf
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
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
 

More from Arab Open University and Cairo University

More from 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
 

Recently uploaded

INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 

Recently uploaded (20)

INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 

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