GATE Operating System Book
Transcript of GATE Operating System Book
-
8/10/2019 GATE Operating System Book
1/12
-
8/10/2019 GATE Operating System Book
2/12
Operating System
For
Computer Science
Information Technology
By
www.thegateacademy.com
http://www.thegateacademy.com/http://www.thegateacademy.com/http://www.thegateacademy.com/http://www.thegateacademy.com/http://www.thegateacademy.com/http://www.thegateacademy.com/http://www.thegateacademy.com/ -
8/10/2019 GATE Operating System Book
3/12
Syllabus Operating System
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
: 080-65700750,[email protected] Copyright reserved. Web: www.thegateacademy.com
Syllabus for Operating System
Processes, Threads, Inter-process communication, Concurrency, Synchronization, Deadlock, CPU
scheduling, Memory management and virtual memory, File systems, I/O systems, Protection and
security.
Analysis of GATE Papers
(Operating System)
Year Percentage of marks Overall Percentage
2013 12.00
8.12
2012 9.33
2011 5.00
2010 7.00
2009 8.00
2008 9.33
2007 9.33
2006 11.33
2005 2.67
2004 7.33
2003 8.00
-
8/10/2019 GATE Operating System Book
4/12
Contents Operating System
THE GATE ACADEMY PVT.LTD. H.O.: #74, KeshavaKrupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
080 65700750 i f @th t d C i ht d W b th t d P i
C O N T E N T S
Chapters Page No.
1. Introduction to Operating System 1 10
Introduction 1
Evolution of Operating System 2 3
Major Achievements 3 5
Operating System Operations 5 6
Micro Kernel Architecture 6 8
Assignment 9
Answer Keys 10 Explanations 10
2. Process Management 11 45
Process 11
Process vs Program 11
Process State 11
Process Creation 12 13
Process Termination 13 14
Process Scheduling 14
Interprocess Communication, Concurrencyand Synchronization 14 17
The Critical Section Problem 17 19
Bakery Algorithm 19 20
Semaphores 20 23
The Readers and Writers Problem 23 26
Monitors 26 29
Solved Examples 30 33
Assignment 1 34 38
Assignment 2 38 41
Answer Keys 42 Explanations 42 45
3. Threads 46 -52
Thread 46
Life Cycle Of Threads 46 47
Multithreading 47
Process Vs Thread 48
User Level and Kernel Level Threads 48 50
Assignment 50 51
Answer Keys 52 Explanations 52
-
8/10/2019 GATE Operating System Book
5/12
Contents Operating System
THE GATE ACADEMY PVT.LTD. H.O.: #74, KeshavaKrupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
080 65700750 i f @th t d C i ht d W b th t d P ii
4. CPU Scheduling 53 77
Basic Concept 53
Schedulers 53
54 Scheduling Methodology 54
CPU Scheduling Algorithm 54 62
Solved Examples 63 67
Assignment 1 68 72
Assignment 2 72 73
Answer Keys 74
Explanations 74 77
5. Deadlocks 78 -92
Definition 78 Resource Allocation Graph 78
Condition for Deadlock 78 79
Deadlock Prevention 79
Deadlock Avoidance 79 82
Deadlock Detection 82 83
Recovery From Deadlock 84
Assignment 1 85 88
Assignment 2 88 89
Answer Keys 90
Explanations 90
92
6. Memory Management 93-134
Introduction 93
Logical and Physical Address Space 93 94
Memory Management Requirements 94 96
Memory Allocation Method 96 102
Paging 102 106
Segmentation 106 109
Page Replacement Algorithm 110 112
Thrashing 112
113
Solved Examples 114 125
Assignment 1 126 128
Assignment 2 128 129
Answer Keys 130
Explanations 130 134
7. File System 135 153
Introdution 135
File Concept 135 137
Access Methods 137
138
-
8/10/2019 GATE Operating System Book
6/12
Contents Operating System
THE GATE ACADEMY PVT.LTD. H.O.: #74, KeshavaKrupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
080 65700750 i f @th t d C i ht d W b th t d P iii
Directory Structure 138 140
Protection 140 144
Free Space Management 144
145 Solved Examples 146 147
Assignment 1 148 149
Assignment 2 150 151
Answer Keys 152
Explanation 152 153
8. I/O System 154 - 172
Kernel I/O Subsystem 154
Disk Structure 154 155
Disk Scheduling 155
157 Disk Management 157 158
RAID 158 159
Solved Examples 160 163
Assignment 1 164 167
Assignment 2 167 168
Answer Keys 169
Explanations 169 172
9. Protection and Security 173 185
Domain of Protection 173
Access Matrix 173 176
The Security Problem 176 178
Solved Examples 179 180
Assignment 1 181 182
Assignment 2 182 183
Answer Keys 184
Explanations 184 185
Module Test 186 199
Test Questions 186 194
Answer Keys 195
Explanations 195 199
Reference Books 200
-
8/10/2019 GATE Operating System Book
7/12
Chapter 1 Operating System
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
080 65700750 i f @th t d C i ht d W b th t d P 1
CHAPTER 1
Introduction to Operating System
What is an Operating System?
An operating system is a collection of programs and utilities. It act as the interface between user
and computer. It creates a user friendly environment. The Operating System act as a ResourceManager. (A Computer system has many resources (Hardware and Software) which may require
for completing a task). The computer uses resources like input/output device, memory, file,
storage space, CPU time and so on. The operating system acts as a manager of these resourcesand allocates them to specific program and users as necessary for their tasks. Therefore we cansay an operating system act as a resource manager. Generally resource sharing in two ways in
time and in space. For example a CPU is a time sharing resource and the main memory is a
space sharing resource. The main difference between in time sharing and in space sharingresource is in time resource is not divided into units, where as in space resources is divided
into units.
Structure of Operating System
The structure of operating system consists of 4 layers; these are hardware, software, systemprogram and application program. The hardware part consists of CPU, main memory, I/O device,Secondary storage etc. The software includes process management routines, memory
management routines, I/O control routines, file management routines. The system programlayer consist of complier, assembler etc. Last one is the application program that depends on
users.
Components of a Computer System
-
8/10/2019 GATE Operating System Book
8/12
Chapter 1 Operating System
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
080 65700750 i f @th t d C i ht d W b th t d P 2
Evolution of Operating System
i.
Serial Processing:Before 1950 the programmer directly interacts with hardware. Therewas no operating system at that time, if the programmer wish to execute a program onthese days, the following steps are necessary.
Type the program on punch card
Convert punched card to card reader
Submit to the computing machine, is there any error, the condition was indicatedby lights.
The programmer examines the registers and main memory to identify the cause of
error.
Take the output of error.
Take the output on the printers.
Then the programmer ready for the next program
This type of processing takes much time and next program should wait for the completion of
previous one. The programs are submitted to the machine one after one. Therefore this
machine is said to be serial processing.
ii. Batch Processing:In older days (before 1960), it was difficult to execute a program usingcomputer. Because the computer located in three rooms. One room for card reader
second room for executing the program third room for printing the result. The user ormachine operator needs to run between these three rooms to complete a job. We can
solve this problem using Batch processing. In batch processing same type of task aregrouped together and execute at a time. The carrier carries the group of job at a time
from one room to another. Therefore the programmer need not to run between these 3rooms several times.
iii. Multiprogramming: Multiprogramming is a technique to execute number of programs
simultaneously by a single processor. In multiprogramming more than one process canreside in main memory at a time. The operating system picks and begins execute one of
the jobs in the main memory.
In non multiprogramming system, the CPU can execute only one program at a time. If therunning program is waiting for any I/O device, the CPU becomes idle, so it will effect the
performance of the CPU. But in multiprocessing environment, any I/O wait happened ina process and then the CPU switches from the job to another job in the job pool. So the
CPU is not idle at any time.
iv. Time Sharing System: Time sharing or multitasking is a logical extension ofmultiprocessing. In time sharing system the CPU selects a job from the ready queue and
switches the CPU to that job. When the time slot is expired the CPU switches from thisjob to another, in this method CPU is shared by different process, so it is said to be Time
Sharing System. The main advantage of time sharing system over the batch processingsystem is the user can interact with the job when it is executing but it is not possible in
batch system. Another advantage of time sharing system is efficient CPU utilization.
v. Parallel System: If a system has more than one processor in close communication,
sharing the computer bus, the clock, memory and peripheral devices, this system is
referred as tightly coupled system. A system consisting of more than one processor andif it is a tightly coupled and then the system is called parallel system. One advantage of
-
8/10/2019 GATE Operating System Book
9/12
Chapter 1 Operating System
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
080 65700750 i f @th t d C i ht d W b th t d P 3
parallel system is increased Throughpu
t. The performance of CPU is measured in terms
of Throughput. The number of jobs completed by a CPU with in a time period is said to be
hrou hput.
Multiprocessor can also save money compared to multiple single system because the
processor can share peripherals, cabinet and power supply. Another advantages ofmultiprocessor system is that they increase reliability.
vi. Distributed System: In distributed system, the processor cant share memory or clock,each processor has its own local memory. The processor communicate one another
though various communication lines. These system are usually called loosely coupled
system. The advantage of distributed system are:
1. Resource sharing2.
Computation speed up
3.
Reliability
vii. Real Time System
Used when there are rigid time requirements on the operating of a processor or the
flow of data.
Systems that control scientific experiments, medical imaging systems, industrial
control systems and some display system are real time systems.
Two types of real time systems are:
A hard real time system:guarantees that critical tasks completed on time. Soft real time system:A less restrictive type of real time system is a soft real
time system. Given their date of deadline support they are risky to use forindustrial control and robotics
Spooling
The expansion of spooling is simultaneous peripheral operations on line. Simultaneous
means for example if two or more user issue print command and the printer accept the
request even the printer is printing some other jobs. The printer printing one job at the
same time the spool disk can load some other jobs.
Operating System Functions
1.
Program creation
2. Programs execution3. Input output operation
4. Error detection
5.
Resource allocation6.
Accounting
7. Protection
Major Achievements
The major achievement of operating system are
Process Management
A process is a program in execution: (A program is passive in nature while a process is active)
A process has resources (CPU time, files) and attribute that must be managed.
-
8/10/2019 GATE Operating System Book
10/12
Chapter 1 Operating System
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
080 65700750 i f @th t d C i ht d W b th t d P 4
Management of Processes Includes:
Process scheduling (priority, time management,)
Creation/termination
Block/Unblock (suspension/resumption)
Synchronization
Communication
Deadlock handling
Debugging
Main Memory Management
Allocation/de-allocation for processes, files, I/O
Maintenance of several processes at a time Keep track of whos using what memory
Movement of process memory to/from secondary storage.
File Management
A file is a collection of related information defined by its creator, commonly files represent
program (both source and object forms) and data.
The operating system is responsible for the following activities in connections with file
management:
File creation and deletion
Directory creation and deletion
Support of primitives for manipulating files and directories
Mapping files onto secondary storage
File backup on stable (non volatile) storage media
I O Management
Buffer caching system
Generic device driver code
Drivers for each device- translate requests into position commands
Secondary Storage Management
Disk, tapes, optical
Free space management ( paging/swapping)
Storage allocation (what data goes where on disk)
Disk scheduling
Networking
Communication system between distributed processors. Getting information about files/processes/etc. on remote machine.
-
8/10/2019 GATE Operating System Book
11/12
Chapter 1 Operating System
THE GATE ACADEMY PVT.LTD. H.O.: #74, Keshava Krupa (third Floor), 30th
Cross, 10th
Main, Jayanagar 4th
Block, Bangalore-11
080 65700750 i f @th t d C i ht d W b th t d P 5
Can use either a message passing or a shared memory model.
Protection
Of files, memory, CPU, etc.
Means controlling of access
Depends on the attributes of the file and user
System Program
Command Interpreters Program that accepts control statements (shell, GUI interface,etc.)
Compilers/linkers
Communication (ftp, telnet, etc.)
System Tailoring
Modifying the operating System program for a particular machine. The goal is to include all thenecessary pieces but not too many extra ones.
Typically a System can support many possible devices but any one installation has only afew of these possibilities.
Plug and play allows for detection of device and automatic inclusion of the code (driver)necessary to drive these devices.
A system is usually a link of many OS routines/modules in order to produce anexecutable code to run the drivers.
Operating System Operations
Modern operating systems are interrupt driven. If there are no processes to execute, no I/O
devices to service and no users to respond, an operating system will quietly waiting forsomething to happen. Events are almost always signaled by the occurrence of an interrupt or a
trap.
Traps and interrupts
are events that disrupt the normal sequence of instruction executed by the
CPU. A trap is an abnormal condition detected by the CPU, that usually is an indicative of anerror.
Trap condition can occur in following ways(a)
Dividing by zero(b)
Trying to access a memory location that does not exists or for which the program does
not have access(c) Executing an instruction with an undefined opcode,
(d)
Trying to access a nonexistent I/O device.
An nt rrupt is a signal sent to the CPU by an external device, typically an I/O device. It is theCPUs equivalent of a pager, a signal requesting the CPU to interrupt its current activities to
attend to the interrupting device needs. A CPU will check interrupts only after it has completedthe processing of one instruction and before it fetches a subsequent one.
The CPU responds to traps and interrupts by saving the current value of the program counterand resetting the program counter to a new address. This allows the CPU to return to the
executing point where the trap or interrupt occurred, after it has executed a procedure for
handling the trap or interrupt.
-
8/10/2019 GATE Operating System Book
12/12