GATE Operating System Book
GATE Operating System Book
For
Computer Science
&
Information Technology
By
www.thegateacademy.com
Syllabus
Operating System
Percentage of marks
2013
12.00
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
Overall Percentage
8.12%
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
Contents
Operating System
CONTENTS
#1.
#2.
Chapters
Page No.
1 10
1
23
35
56
68
9
10
10
Process Management
11 45
11
11
11
12 13
13 14
14
#3.
Introduction
Evolution of Operating System
Major Achievements
Operating System Operations
Micro Kernel Architecture
Assignment
Answer Keys
Explanations
Process
Process vs Program
Process State
Process Creation
Process Termination
Process Scheduling
Interprocess Communication, Concurrency
and Synchronization
The Critical Section Problem
Bakery Algorithm
Semaphores
The Readers and Writers Problem
Monitors
Solved Examples
Assignment 1
Assignment 2
Answer Keys
Explanations
14 17
17 19
19 20
20 23
23 26
26 29
30 33
34 38
38 41
42
42 45
Threads
46 -52
46
46 47
47
48
48 50
50 51
52
52
Thread
Life Cycle Of Threads
Multithreading
Process Vs Thread
User Level and Kernel Level Threads
Assignment
Answer Keys
Explanations
THE GATE ACADEMY PVT.LTD. H.O.: #74, KeshavaKrupa (third Floor), 30th Cross, 10th Main, Jayanagar 4th Block, Bangalore-11
: 080-65700750, [email protected] Copyright reserved. Web: www.thegateacademy.com
Page i
Contents
#4.
#5.
#6.
#7.
Operating System
CPU Scheduling
53 77
53
53 54
54
54 62
63 67
68 72
72 73
74
74 77
Basic Concept
Schedulers
Scheduling Methodology
CPU Scheduling Algorithm
Solved Examples
Assignment 1
Assignment 2
Answer Keys
Explanations
Deadlocks
78 -92
78
78
78 79
79
79 82
82 83
84
85 88
88 89
90
90 92
Definition
Resource Allocation Graph
Condition for Deadlock
Deadlock Prevention
Deadlock Avoidance
Deadlock Detection
Recovery From Deadlock
Assignment 1
Assignment 2
Answer Keys
Explanations
Memory Management
93-134
93
93 94
94 96
96 102
102 106
106 109
110 112
112 113
114 125
126 128
128 129
130
130 134
Introduction
Logical and Physical Address Space
Memory Management Requirements
Memory Allocation Method
Paging
Segmentation
Page Replacement Algorithm
Thrashing
Solved Examples
Assignment 1
Assignment 2
Answer Keys
Explanations
File System
135 153
135
135 137
137 138
Introdution
File Concept
Access Methods
THE GATE ACADEMY PVT.LTD. H.O.: #74, KeshavaKrupa (third Floor), 30th Cross, 10th Main, Jayanagar 4th Block, Bangalore-11
: 080-65700750, [email protected] Copyright reserved. Web: www.thegateacademy.com
Page ii
Contents
#8.
#9.
Directory Structure
Protection
Free Space Management
Solved Examples
Assignment 1
Assignment 2
Answer Keys
Explanation
Operating System
138 140
140 144
144 145
146 147
148 149
150 151
152
152 153
I/O System
154 - 172
154
154 155
155 157
157 158
158 159
160 163
164 167
167 168
169
169 172
173 185
173
173 176
176 178
179 180
181 182
182 183
184
184 185
Domain of Protection
Access Matrix
The Security Problem
Solved Examples
Assignment 1
Assignment 2
Answer Keys
Explanations
Module Test
186 199
186 194
195
Test Questions
Answer Keys
Explanations
Reference Books
195 199
200
THE GATE ACADEMY PVT.LTD. H.O.: #74, KeshavaKrupa (third Floor), 30th Cross, 10th Main, Jayanagar 4th Block, Bangalore-11
: 080-65700750, [email protected] Copyright reserved. Web: www.thegateacademy.com
Page iii
Chapter 1
Operating System
CHAPTER 1
Introduction to 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
Page 1
Chapter 1
Operating System
Serial Processing: Before 1950 the programmer directly interacts with hardware. There
was no operating system at that time, if the programmer wish to execute a program on
these days, the following steps are necessary.
Submit to the computing machine, is there any error, the condition was indicated
by lights.
The programmer examines the registers and main memory to identify the cause of
error.
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 using
computer. 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 or
machine 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 are
grouped 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 3
rooms several times.
iii. Multiprogramming: Multiprogramming is a technique to execute number of programs
simultaneously by a single processor. In multiprogramming more than one process can
reside 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 the
running 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 in
a 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 of
multiprocessing. 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 this
job 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 processing
system 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 and
if it is a tightly coupled and then the system is called parallel system. One advantage of
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
Page 2
Chapter 1
Operating System
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 execution
3. Input output operation
4. Error detection
5. Resource allocation
6. 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.
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
Page 3
Chapter 1
Operating System
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:
I/O Management
Networking
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
Page 4
Chapter 1
Operating System
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 the
necessary pieces but not too many extra ones.
Typically a System can support many possible devices but any one installation has only a
few 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 an
executable code to run the drivers.
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
Page 5