Operating System
Total Page:16
File Type:pdf, Size:1020Kb
OPERATING SYSTEM For COMPUTER SCIENCE OPERATING SYSTEM . SYLLABUS Processes, threads, interprocess communication, concurrency and synchronization. Deadlock. CPU scheduling. Memory management and virtual memory. File systems. ANALYSIS OF GATE PAPERS Exam Year 1 Mark Ques. 2 Mark Ques. Total 2003 2 5 12 2004 3 4 11 2005 - 2 4 2006 1 8 17 2007 2 6 14 2008 2 5 12 2009 2 5 12 2010 3 2 7 2011 4 2 8 2012 1 4 9 2013 2 4 10 2014 Set-1 2 3 8 2014 Set-2 1 3 7 2014 Set-3 1 3 7 2015 Set-1 2 4 10 2015 Set-2 2 3 8 2015 Set-3 2 2 6 2016 Set-1 1 4 9 2016 Set-2 1 3 7 2017 Set-1 2 2 6 2017 Set-2 2 2 6 2018 4 6 10 © Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission CONTENTS Topics Page No 1. PROCESS AND DEADLOCK 1.1 Process Concept 1 1.2 Process States 1 1.3 Degree of Multiprogramming 1 1.4 Process Control Block 1 1.5 Threads 1 1.6 CPU Scheduling 2 1.7 Scheduling Algorithms 3 1.8 Deadlock 8 1.9 Three Types of Problems 12 1.10 Procedure Consumer Problem 12 1.11 Printer And Spooler Problem 13 1.12 Solution to IPC/ Synchronization 13 1.13 Solution to Producer Consumer Problem using Semaphores 15 1.14 Solution to Reader & Writer Problem 15 Gate Questions 17 2. MEMORY MANAGEMENT 2.1 Introduction 53 2.2 Single Partition Allocation 55 2.3 External & Internal Fragmentation 56 2.4 Segmentation 58 2.5 Fragmentation 59 2.6 Virtual Memory 59 2.7 Page Replacement 60 2.8 Demand Paging 61 2.9 Page-Replacement 61 2.10 Counting Algorithms 63 2.11 Allocation of Frames 63 2.12 Thrashing 64 3. INTERRUPTS Gate Questions 65 3.1 Introduction 78 © Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 3.2 Interrupts 78 3.3 Applications I/O Interface 79 3.4 Block and Character Devices 79 3.5 Kernel I/O subsystems 79 3.6 Performance 81 3.7 Stable-Storage Implementation 83 4. FILE-MANAGEMENTGate Questions 85 4.1 Introduction 88 4.2 File Concept 88 4.3 Access Methods 89 4.4 Single-Level Directory 91 4.5 Types of Access 91 4.6 Allocation Methods 92 4.7 Free-Space Management 94 4.8 Directory Implementation 94 Gate Questions 96 5. ASSIGNMENT QUESTIONS 99 © Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 1 PROCESS & DEADLOCK 1.1 PROCESS suspended wait state (i.e. secondary storage).MTS reduces Process is just an executing program, degree of multiprogramming. including the current values of the program counter, registers, and variables. (c) STS (Short Term Scheduler): It is responsible to pick one process 1.2 PROCESS STATES from ready state and allocate it to Figure shows all process states. CPU.STS saves and loads context of a process in its PCB while switching. LTS: Job Scheduler MTS: Swapping STS: CPU Scheduler/Dispatcher STS is faster than LTS. Process with respect to their execution time are divided into two types: (a) CPU Bound Process: - Processes State 2, 3, and 4: Process in these states which require more CPU time are reside in RAM. called CPU Bound Process. The State 5, 6: Process is shifted to secondary process will spend more time in storage deliberately for some time. ready state. (b) IO Bound Process: - Processes 1.2.1 Three types of scheduler: which require more IO time are (a) LTS (Long Term Scheduler): It is the called IO Bound Process. responsibility of LTS to create a process and bring it in ready state. 1.3 Degree of Multiprogramming LTS decides which programs are The number of processes in the memory at admitted to system for execution. any point of time is called degree of multiprogramming. LTS should select good (b) MTS (Medium Term Scheduler): Its combination of CPU bound and IO bound responsibility is in two cases. When processes. LTS controls degree of ready stated becomes crowded so multiprogramming. that OS doesn’t have resources (RAM) to accommodate large 1.4 PROCESS CONTROL BLOCK number of processes in ready state, Every process has its own PCB. PCB is they can be moved by MTS to stored in RAM. suspended_ready state. Attributes: pid, process state, PC (program Also, when resources (RAM) gets counter),GPR(general purpose exhausted in wait state due to registers),Priority, List of open files, crowding, MTS shifts them to Protection & security. © Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission The set of these attributes is called context. Program Counter. Thread share data, code, Context is stored in PCB. memory, files, address space, File descriptor table, so on. 1.5 THREADS Threads are light weight processes. Each thread has its own Stack, Registers and User Level Threads Kernel Level Threads User level threads are dependent. Kernel level threads are independent. They are faster. They are comparatively slower but faster than a process. They are scheduled by thread library. They are scheduled by OS. They have less context. They have more context. Blocking IO calls: If one thread Non-Blocking IO calls: If one thread other thread of that process can run. blocks for IO, OS schedules another for execution. 1.6 CPU SCHEDULING (b) Burst Time SCHEDULING CRITERIA The time required for the process to complete its execution is called Burst The scheduling criteria that are used Time. includes (c) Completion Time The time when the process has i) CPU utilization completed its execution is called The CPU should be kept as busy as completion time. possible. CPU utilization may range (d) Turnaround time from 0 to 100 per cent. In a real system, The interval from the time of it should range from 40 per cent (for a submission of a process to the time of lightly loaded system) to 90 per cent completion is the turnaround time. TAT (for a heavily used system). = CT – WT. (e) Waiting time ii) Throughput The amount of time a process spends If the CPU is busy executing processes, waiting in the ready queue. then work is being done. One measure WT = TAT-BT. of work is the number of processes that (f) Response time are completed per time unit, called Response time, is the amount of time it throughput. For long processes, this takes to start responding, but not the rate may be one. time that it takes to output that response. The turnaround time is Various Time Measures related to generally limited by the speed of the CPU Scheduling: output device. The goal is to maximize CPU (a) Arrival Time Utilization, minimize average Turn The time when the process arrived into ready state is called arrival time. © Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission around Time, and minimize Waiting This reduction is substantial. Thus, the Time of processes. average waiting time under a FCFS policy is generally not minimal. 1.7 SCHEDULING ALGORITHMS The FCFS scheduling algorithm is non- preemptive. Once, the CPU has been 1.7.1 First-Come, First-Served allocated to a process, that process keeps Scheduling (FCFS) the CPU until it releases the CPU, either by Criteria: Arrival Time terminating or by requesting I/O. Mode : Non Preemptive Data Structure: Queue 1.7.2 Shortest –Job-First Scheduling Tie Breaker : Process Number (SJF) The average waiting time under the FCFS Criteria: Burst Time policy, however, is often quite long. Mode : Non Preemptive Consider the following set of processes Data Structure: Min Heap that arrive at time 0, with the length of the Tie Breaker : Arrival Time CPU- burst time given in milliseconds: Shortest Job First has minimum average waiting time among all CPU scheduling PROC ARRIVA BURS CT TA W algorithms. ESS L TIME T T T Consider the following set of process, with TIME the length of the CPU burst time given in P1 0 24 24 24 0 milliseconds: P2 0 3 27 27 24 PROCESS BURST TIME P3 0 3 30 30 27 P1 6 P2 8 P3 7 GANTT CHART: P4 3 Using SJF scheduling, we would schedule P1 P2 P3 these processes according the following 0 24 25 27 28 30 Gantt chart: Now, the waiting time is 0 milliseconds for P4 P1 P3 P2 process P1, 24 milliseconds for process P2, 0 3 9 16 24 and 27 milliseconds for process P3. Thus, 0+24+27 The waiting time is 3 milliseconds for the average waiting time = = 3 process P1, 16 milliseconds for process P2, 17milliseconds. 9 milliseconds for process P3, and 0 This example also shows Convoy effect. milliseconds for process P4. FCFS suffers from convoy effect. Thus, the average waiting time = If the processes arrive in the order P2, P3, 3 16 9 0 P1, however, the results will be as shown in 4 = 7 milliseconds. the following Gantt chart: If we were using the FCFS scheduling P2 P3 P1 scheme, then the average waiting time 0 3 6 30 would be 10.25 milliseconds. The SJF scheduling algorithm is provably 6+0+3 Now, the average waiting time = = 3 optimal, in that it gives the minimum 3milliseconds. average waiting time for a given set of © Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission processes.