Cs30101:: Operating Systems

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 159

CS30101:: OPERATING SYSTEMS

Credits: 03
Teaching Scheme: - Theory 3 Hrs/Week
Prerequisites: Data Structures and Algorithms, Computer
Organization.
Objectives:
• Identify the role of operating systems and explain the
different structures operating systems.
• Describe OS support for processes/threads, and virtual
memory, I/O and file systems.
• Evaluate processes and/or threads synchronization
mechanisms and explain deadlock conditions and ways to
resolve them.
• Identify the different design and implementation
concepts for Unix/Linux
• Use Inter-Process Communication techniques under
Unix/Linux.
• Mapping with PEOs: II, III, (d).
1
Syllabus
Unit I
Introduction to OS (8+1 Hrs)

A. Introduction to OS: What is OS, Interaction of OS and


hardware, Goals of OS, Basic functions of OS, OS Services,
System Calls.
Types of OS: Batch, Multiprogramming, Time sharing, Parallel,
Distributed & Real-time OS.
Structures of OS: Monolithic, Layered, Ringed, Virtual Machines,
Exokernels, Client-server model, Microkernels.
Shell: Linux commands and shells, shell programming, AWK
programming.
Introduction to Mobile OS: Architecture & Overview of Android
OS.

B. Overview of Linux and Windows 2000 architecture

2
Unit II
Process Management (8+1 Hrs)

A. Processes: Process Concept, Process States: 2, 5, 7 state


models, Process Description, Process Control
Threads: Multithreading models, Thread implementations –
user level and kernel level threads.
Symmetric Multiprocessing.
Concurrency: Issues with concurrency, Principles of
Concurrency
Mutual Exclusion: H/W approaches, S/W approaches:
Semaphores, Mutex, Monitors. Classical Problems of
Synchronization: Readers-Writers problem, Producer
Consumer problem, Dining Philosopher problem.
B. IPC: Shared memory, Message passing. Sleeping Barber
problem.

3
Unit III
Scheduling and Deadlock (8+1 Hrs)

A. Uniprocessor Scheduling: Types of Scheduling -


Preemptive, Non-preemptive, Long-term, Medium-term,
Short-term, Scheduling Criteria.
Scheduling Algorithms: FCFS, SJF, RR, Virtual Round Robin,
Priority
Multiprocessor Scheduling: Granularity, Design Issues,
Process Scheduling
Deadlock: Principles of deadlock, Deadlock Prevention,
Deadlock Avoidance, Deadlock Detection, Deadlock Recovery.

B. Thread Scheduling, Real Time Scheduling.

4
Unit IV
Memory Management (8+1 Hrs)

A. Memory Management concepts: Memory Management


requirements, Memory Partitioning: Fixed, Dynamic
Partitioning, Buddy Systems. Placement Strategies: First Fit,
Best Fit, and Worst Fit, Fragmentation, Swapping, Paging,
Segmentation, Address translation.
Virtual Memory: Concepts, VM with Paging, Page Table
Structure, Inverted Page Table, Translation Lookaside Buffer,
VM with Segmentation.
OS policies for Virtual Memory: Fetch, Placement,
Replacement, Resident Set management, Cleaning Policy,
Load Control.
Page Replacement Policies: FIFO, LRU, Optimal, Random.
Page Buffering. Thrashing.
B. VM with combined paging and segmentation, Working Set
Model.

5
Unit V
I/O and File Management
(8+1 Hrs)
A. I/O management: I/O Devices, OS design issues for I/O
management, I/O Buffering.
Disk Scheduling: FCFS, SCAN, C-SCAN, SSTF.
File Management: Concepts, File Organization, File
Directories, File Sharing. Record Blocking, Secondary Storage
Management, Free Space management, Security.
Case study: Process Management, Concurrency, Scheduling,
Memory Management, I/O Management, File Management in
LINUX
B: Organization of I/O functions,Disk caches

6
Books
Text Books
1. “Operating Systems”, Stalling William, Pearson
Education, ISBN: 0-13-031999- 6, 4th Edition.
2. “Operating System Concepts”, Silberschatz A., Galvin P.,
Gagne G., John Wiley and Sons, ISBN: 9971-51-388-9, 6th
Edition.
Reference Books
1. “Modern Operating Systems”, Tanenbaum Andrew S.,
Prentice Hall India, ISBN: 81-7808-447-3, 2nd Edition.
2. “Unix Concepts and Applications”, Das Sumitabha, Tata
McGraw Hill, ISBN: 0-07-053475-6, 3rd Edition.

7
Marking Scheme
Parameter Marks % of Marks

ESE 100 60

MSE 20 100

Sr. No. TA Parameter


15 100 % of Marks
1 Home Assignment (30 Marks) 30
2 Tutorial (30 Marks) 30
3 Test (30 Marks) 30
Total (90 Marks) 90 marks converted to 20 90
marks

8
Scheme of Marking for continuous assessment
of Tutorial courses

Sr Parameter % of
No Marks

1 Regularity and Interaction (2 Marks) 20

2 Method based evaluation 40


-Timely submission of assignment
(2 Marks)
-Programming/ coding style and guidelines used
(2 Marks)
3 Practical Assignments 40
-Originality of assignment (Innovativeness)
(2 Marks)
-Understanding the theme and use of assignment
performed (2 Marks)

08/06/11 9
Scheme of Marking for continuous assessment of Lab
courses
Sr Parameter % of Marks
No

1 Regularity and Interaction (2 Marks) 20

2 Method based evaluation 40


-Timely submission of assignment
(2 Marks)
-Programming/ coding style and guidelines used
(2 Marks)

3 Practical Assignments 40
-Originality of assignment (Innovativeness)
(2 Marks)
-Understanding the theme and use of assignment
performed (2 Marks)

10
Unit I

Introduction to Operating System

11
Block Diagram of a Computer (Logical)

Vishal
12
Kaushal
Operating System (OS)
• What do you do with just computer hardware?
– If someone gives you a computer with no software
whatsoever, how do you get it to do anything?
– You write a program that runs on the hardware

• In the early days, that was the way it worked ...


– You started with just the bare hardware
– You wrote a program that did everything:
• Including managing all aspects of the hardware
• Including solving your particular problem

• Your program was all the computer did!

13
Without an OS
• Each program runs directly on the hardware
• Each program must do everything
• Each program needs to know the details of the hardware and
how to use it
• If the hardware changes, the program must change as well
• The hardware supports only one program at a time - each
user must wait until the previous program is done to “share”
the hardware with other users.
• Writing programs is incredibly complex and expensive
• OS is like an extended machine to provide a better interface
for convenience.

14
Four Components of a Computer System:

15
Computer System Structure

 Computer system can be divided into four components:


 Hardware – provides basic computing resources
 CPU, memory, I/O devices

 Operating system
 Controls and coordinates use of hardware among various
applications and users

 Application programs – define the ways in which the system


resources are used to solve the computing problems of the users
 Word processors, compilers, web browsers, database systems,
video games

 Users
 People, machines, other computers

16
Operating System (OS)
• Integrated set of programs that controls the resources of a
computer system
• Provides its users with an interface which is more convenient
to use than bare machine
• Directly sits on top of the hardware and controls it
• Manages computer hardware
• Provides a basis for application programs
• Acts as an intermediary between computer user and
computer hardware

17
Introduction
• “An operating system is similar to a government. Like a
government, it performs no useful function by itself. It simply
provides an environment within which other programs can do
useful work”

• “The fundamental goal of computer systems is to execute user


programs and to make solving user problems easier”

18
Views of an Operating System

• Resource Allocator
– Operating system manages or allocates resources
– What resources?
• CPU time, RAM Memory, disk & other I/O devices, interrupt
numbers (IRQ’s), files, network ports & sockets, and other
software resources
– Who uses the resources?
• Resource users: One or more user processes & threads
• Control Program
– Operation and control of hardware devices
– Implements security and protection
– Execution of user program to prevent errors and prevent improper
use of the computer

19
Goals of an OS
 Execute user programs and make solving user
problems easier
 Make the computer system convenient to use
 Use the computer resources in an efficient
manner
 Ability to evolve
 Can you think of reasons which make evolution
necessary?
 H/W changes, new services, fixes
 Different design goals for different OS
 Mainframes, PC, Handheld

Vishal
20
Kaushal
The Role of an OS
• A computer is a set of resources for the movement, storage, and
processing of data.
• The OS is responsible for managing these resources.

21
Operating System as Software

•The OS functions in the same way as an ordinary computer software

•It is a program that is executed by the CPU

•The OS frequently relinquishes control and must depend on the


processor to allow it to regain control.

22
OS as Resource Manager

23
•This figure suggests the main resources that are managed by the OS.

•A portion of the OS is in main memory.


• This includes the kernel, or nucleus, which contains the most frequently
used functions in the OS
• and other portions of the OS currently in use.

•The remainder of main memory contains user programs and data.


• The allocation of this resource (main memory) is controlled jointly by the
OS and memory management hardware in the processor.

• The OS decides when an I/O device can be used by a program in execution and
controls access to and use of files.

•The processor itself is a resource, and the OS must determine how much
processor time is to be devoted to the execution of a particular user program.
• In the case of a multiple-processor system, this decision must span all of the
processors.
24
How are Hardware resources shared?
• Memory and disk space
– programs use different regions Program A
– space multiplexed Program B
• Printers (and other peripherals)
– programs line up and wait

• CPU
– programs time share
– time is split into slices, with each Program B Program A
program getting several slices
– time multiplexed B A
A
B
C
25
Evolution of Operating Systems
Operating systems will evolve over time

1. Hardware upgrades plus new types of hardware: e.g. early


versions of UNIX and the Macintosh operating system did not employ a paging
mechanism because they were run on processors without paging hardware.
 Subsequent versions of these operating systems were modified to exploit
paging capabilities.
2. New services: In response to user demand or in response to the
needs of system managers, the OS expands to offer new services.
e.g. if it is found to be difficult to maintain good performance for users with
existing tools, new measurement and control tools may be added to the OS.
3. Fixes:Any OS has faults.
 These are discovered over the course of time and fixes are made.
 Of course, the fix may introduce new faults.

26
Common Tasks by OS

Vishal
27
Kaushal
Basic function of OS:

• Process Management

• Main memory management

• Secondary storage management

• I/O Subsystem Management

• File Management

28
1. Process Management
 A process is a program in execution. It is a unit of work within the
system. Program is a passive entity, process is an active entity.
 Process needs resources to accomplish its task
 CPU, memory, I/O, files
 Initialization data
 Process termination requires reclaim of any reusable resources
 Single-threaded process has one program counter specifying
location of next instruction to execute
 Process executes instructions sequentially, one at a time, until
completion
 Multi-threaded process has one program counter per thread
 Typically system has many processes, some user, some operating
system running concurrently on one or more CPUs
 Concurrency by multiplexing the CPUs among the processes /
threads

29
Process Management Activities
The operating system is responsible for the following activities in connection
with process management:

 Creating and deleting both user and system processes

 Suspending and resuming processes

 Providing mechanisms for process synchronization

 Providing mechanisms for process communication

 Providing mechanisms for deadlock handling

30
2. Main Memory Management
 Main memory -array of words/bytes

 All data in memory before and after processing

 All instructions in memory in order to execute

 Memory management determines what is in memory when

 Optimizing CPU utilization and computer response to users

 Memory management activities

 Keeping track of which parts of memory are currently being used and by
whom

 Deciding which processes (or parts thereof) and data to move into and
out of memory

 Allocating and deallocating memory space as needed

31
3. Secondary Storage Management
 Main memory is small and volatile
 Secondary storage is large and nonvolatile

 OS activities related to disk management include


 Free space management
 Storage allocation
 Disk scheduling

32
4. I/O Subsystem management

 One purpose of OS is to hide peculiarities of hardware devices from the user

 I/O subsystem responsible for

 Memory management of I/O including

 buffering (storing data temporarily while it is being transferred),

 caching (storing parts of data in faster storage for performance),

 spooling (the overlapping of output of one job with input of other jobs)

 General device-driver interface

 Drivers for specific hardware devices

33
5. File Management
 OS provides uniform, logical view of information storage
 Abstracts physical properties to logical storage unit - file
 Each medium is controlled by device (i.e., disk drive, tape drive)
 Varying properties include access speed, capacity, data-transfer rate,
access method (sequential or random)
 File-System management
 Files usually organized into directories

34
FS Management Activities
 Creating and deleting files
 Creating and deleting directories
 Supporting primitives for manipulating files and directories
 Mapping files onto secondary storage
 Backing up files on stable (non-volatile) storage media

Vishal
35
Kaushal
OS Services

A view of OS services Vishal


36
Kaushal
Operating System Services
 Operating-system provides certain services to programs and users of
that program.(For convenience of programmers)
 User interface - Almost all operating systems have a user
interface (UI)
 Varies between Command-Line (CLI), Graphics User Interface
(GUI), Batch
 Program execution - The system must be able to load a program
into memory and to run that program & end execution, either
normally or abnormally (indicating error)
 I/O operations - A running program may require I/O, which may
involve a file or an I/O device
 For protection & security IO done by OS not by user

37
Operating System Services (Cont)
 File-system manipulation - The file system is of particular interest.
Obviously, programs need to read and write files and directories,
create and delete them, search them, list file Information,
permission management.

 Communications – Processes may exchange information, on the


same computer or between computers over a network
 Communications may be via shared memory(Tightly coupled
system) or through message passing(Loosely coupled system)
packets moved by the OS

38
Operating System Services (Cont)
 Error detection – OS needs to be constantly aware of possible
errors
 May occur in the CPU and memory hardware(memory
error,power failure)
 In I/O devices(connection failure in n/w)
 In user program(access to illegal memory, arithmetic overflow)
 For each type of error, OS should take the appropriate action
to ensure correct and consistent computing.
 Debugging facilities can greatly enhance the user’s and
programmer’s abilities to efficiently use the system

39
Operating System Services (Cont)
 Another set of OS functions exists for ensuring the efficient
operation of the system itself via resource sharing
 Resource allocation - When multiple users or multiple
jobs running concurrently, resources must be allocated to
each of them
 Many types of resources - Some (such as CPU cycles,
main memory, and file storage) may have special
allocation code, others (such as I/O devices) may have
general request and release code
 Accounting - To keep track of which users use how much
and what kinds of computer resources

40
Operating System Services (Cont)
 Protection and security - The owners of information
stored in a multiuser or networked computer system may
want to control use of that information, concurrent
processes should not interfere with each other
 Protection involves ensuring that all access to system
resources is controlled
 Security of the system from outsiders requires user
authentication(password) , defending external I/O
devices modem,NIC from invalid access attempts

41
User – OS Interface
• GUI
– Graphical User Interface
– Desktop, icons, mouse
• CLI
– Command Line Interface
– Allows direct command entry
– Sometimes implemented in kernel, sometimes by systems
program
– Command interpreter
– Windows: Command shell
– UNIX/LINUX: Terminal – bash, ksh, csh: shells
– Built-in commands vs external commands

Vishal
42
Kaushal
User Operating System Interface - GUI
 User-friendly desktop metaphor interface

 Usually mouse, keyboard, and monitor

 Icons represent files, programs, actions, etc

 Various mouse buttons over objects in the interface cause various


actions (provide information, options, execute function, open directory
(known as a folder)

 Invented at Xerox PARC in 1973

 Many systems now include both CLI and GUI interfaces

 Microsoft Windows is GUI with CLI “command” shell

 Apple Mac OS X as “Aqua” GUI interface with UNIX kernel underneath


and shells available.

43
The Mac OS X GUI

44
User Operating System Interface - CLI
Command Line Interface (CLI) or command interpreter allows direct command
entry

 Sometimes implemented in kernel, sometimes by systems program

 Sometimes multiple flavours implemented – shells

 BASH, C, Korn Bourne

 Primarily fetches a command from user and executes it

 Sometimes commands built-in, sometimes just names of


programs

 If the latter, adding new features doesn’t require shell


modification

45
Bourne Shell Command Interpreter

46
Protection and Control
• Ensuring proper operation of the operating system, and
programs
• Examples
(a) only certain users can access certain files;
(b) restricted access to operating system parts of RAM;
(c) restrictions about which instructions can be executed by
applications;
(d) restricted access to RAM of other processes

47
Protection

• A main way that modern operating systems provide


protection is through use of
dual-mode hardware features
• User-mode & kernel mode
• Hardware boots in kernel mode; switches to user-
mode when running user processes
• System call or interrupt enables switch back to kernel
mode

48
Protection modes

• User mode
– limited access to RAM memory; just the memory of a
single program running
– limited access to machine instructions; illegal to
execute I/O instructions, interrupt management
instructions and some others
• kernel mode
– access to all RAM memory
– access to all machine instructions
• User vs. kernel mode implemented as a bit in CPU

49
So , if we have these protection modes, how does a
process gain access to the OS?

How can a user process request an operation or function be


carried out by the operating system?

50
System Calls
 User programs are not allowed to access system resources
directly. They must ask the OS to do that for them.

 OS provides a set of functions that can be called by user


programs to request for OS services. These functions are called
“system calls”
 System calls run in kernel mode.

 They can be called by executing a special instruction (trap or


software interrupt) which causes processor to switch to the kernel
mode and jump to a previously defined location in the kernel.

 When the system call finishes, processor returns to the user


program and runs in user mode.

51
Dual Mode Operation

Figure : Transition from User to Kernel Mode

Kernel mode is also called Supervisor mode


System Calls
 System calls provide the interface between a running program and the
operating system.

 Generally available as assembly-language instructions.

 Languages defined to replace assembly language for systems programming


allow system calls to be made directly (e.g., C, C++)

 Mostly accessed by programs via a high-level Application Program Interface


(API) rather than direct system call use.

 Three most common APIs are Win32 API for Windows, POSIX API for
POSIX-based systems (including virtually all versions of UNIX, Linux, and
Mac OS X), and Java API for the Java virtual machine (JVM)

 Why use APIs rather than system calls?

53
Example of System Calls
 System call sequence to copy the contents of one file to another file

How system calls are used


54
API
• An API is a set of functions provided by an operating
system or other system software.
• An application program calls the functions to request the
services.
• An API clearly defines how to call functions and what the
results are. (API is specification, not implementation)
• Examples: APIs for file system, graphics user interface,
networking, etc

Vishal
55
Kaushal
Advantages of using APIs
1. Portability: User programs that follow the API’s
definition are portable.
2. An API can provide a common interface for
different implementations of a service.
For example, the UNIX file system API is the same for all
kinds of devices.
3. Using an API allows upgrading system software
without changing user programs
4. APIs are faster than system call as there is no need
of mode switch.

56
System Call Implementation
 Typically, a number associated with each system call

 System-call interface maintains a table indexed according to these


numbers

 The system call interface invokes intended system call in OS kernel and
returns status of the system call and any return values

 The caller need know nothing about how the system call is implemented

 Just needs to obey API and understand what OS will do as a result call

 Most details of OS interface hidden from programmer by API

 Managed by run-time support library (set of functions built into


libraries included with compiler)

57
API – System Call – OS Relationship

58
Steps in Making a System Call

There are 11 steps in making the system call


count=read (fd, buffer, nbytes) 59
Standard C Library Example
 C program invoking printf() library call, which calls write() system call

60
System Call Parameter Passing
 Often, more information is required than simply identity of desired system
call
 Exact type and amount of information vary according to OS and call
 Three general methods used to pass parameters to the OS
 Simplest: pass the parameters in registers
 In some cases, may be more parameters than registers
 Parameters stored in a block, or table, in memory, and address of block
passed as a parameter in a register
 This approach taken by Linux and Solaris
 Parameters placed, or pushed, onto the stack by the program and
popped off the stack by the operating system
 Block and stack methods do not limit the number or length of parameters
being passed

61
Parameter Passing via Table

62
Types of System Calls

1. Process control

2. File management

3. Device management

4. Information maintenance

5. Communications

6. Protection

63
Examples of Windows and Unix System Calls

64
65
Differences between library functions and system
calls

 System calls run in kernel-mode but library functions run in


user-mode and may call system calls.
 System calls are not linked to user programs.
 There are only a small number of system calls.

66
Types of Operating System:

08/06/11 67
1.Batch OS
• First OS
• Developed around mid 1950s by GM
• IBSYS had become quite famous by early 1960s
• Special piece of software called monitor
• User submits the job on cards or tape to a computer
operator who batches the job together sequentially and
places the entire batch on an input device for use by the
monitor
• Monitor loads one job, executes it, then loads the next
and so on

Vishal
68
Kaushal
Batch Systems:

Memory Layout for a Simple Batch System

69
Batch OS
• Monitor controls sequence of events
– Must always be in memory and available for
execution
– Called resident monitor
– Rest of the monitor is utilities loaded as subroutines
when required
– Executes in kernel mode (contrast with user mode)
• Job is placed in user program area and control is passed
to it
• Upon completion, the job returns the control to the
monitor which proceeds with reading the next job
• Results of each job are sent to an output device
• JCL: Job Control Language – meta instructionsVishal
70
Kaushal
Batch Systems:

 Bring cards to 1401


 Read cards onto input tape
 Put input tape on 7094
 Perform the computation, writing results to output tape
 Put output tape on 1401, which prints output

71
Batch Systems:

Structure of a typical FMS job


Issues
CPU idle during I/O operations
CPU time is wasted; CPU utilization is low
72
2. Multiprogramming Systems:

 Multiple jobs in memory


Job 3
 Protected from one another

Job 2  Operating system protected from

Memory each job as well


partitions Job 1
 Resources (time, hardware) split
between jobs
Operating
 Still not interactive
system
 User submits job

 Computer runs it
Increases CPU utilization
Job pool-jobs waiting on disk for  User gets results minutes
allocation into memory
(hours, days) later
Job scheduling-selection of job from
pool
73
CPU scheduling
Uniprogramming

Processor must wait for I/O instruction to complete before preceding

74
Multiprogramming

• When one job needs to wait for I/O, the processor can switch to the
other job

75
Multiprogramming

It is the central theme of modern operating


systems 76
3. Time-sharing or Multitasking:
 Fast CPU switching between programs : Idea is to give a feeling of
concurrency

 CPU switches to another program


 When current program blocks
 When its currently allocated CPU time-interval ends
 Also called multitasking
 logical extension in which CPU switches jobs so frequently that users
can interact with each job while it is running, creating interactive
computing
 Response time should be < 1 second
 Each user has at least one program executing in memory process
 If several jobs ready to run at the same time CPU scheduling
 If processes don’t fit in memory, swapping moves them in and out to
run
 Virtual memory allows execution of processes not completely in
memory
77
Batch Multiprogramming versus Time Sharing

78
4. Parallel System/Multiprocessor/Tightly coupled:
 As like multiprocessor system have more than one processors in
close communication ,sharing the computer, bus clock & sometimes
memory & peripheral devices.
 Referred to as tightly coupled system.
 Advantage
1. Throughput: get more work done in less time, Increases throughput
2. Economical :It saves money because process can share peripherals,
mass storage and power supply.
3. Increases the reliability: Ability to continue providing service
proportional to the level of surviving hardware -graceful
degradation -> fault tolerant

79
4. Parallel System:
 Symmetric multiprocessing (SMP)
Peer processors
 Each processor runs an identical copy of the operating system.
 Many processes can run at once without performance drop.
 Most modern operating systems support SMP.
 Ex: Solaries 5,Win2000

 Asymmetric multiprocessing
 Each processor is assigned a specific task; master processor
schedules and allocated work to slave processors.
 More common in extremely large systems
 Ex: Solaries 4,
80
SMP vs ASMP

Vishal
81
Kaushal
5. Distributed System

A distributed system is:

A collection of independent computers that appears


to its users as a single coherent system.

82
5. Distributed System
 A collection of heterogeneous nodes connected by one or more
interconnection networks which provides access to system-wide shared
resources and services.

 More than one physical computer, each consisting of CPUs, local memory,
and possibly stable storage, and I/O paths to connect it with the
environment.

 Interconnections: The processors communicate with one another through


various communication lines such as high speed buses or telephone lines.

 Also known as loosely coupled system.

EX: Internet LAN

83
CPU CPU CPU
5. Distributed System
 Advantages of distributed systems. Memory Memory Memory
 Resources Sharing
 Computation speed up – load sharing
 Reliability
 Communications
 Requires networking infrastructure.
 Ex: Local area networks (LAN) or Wide area networks (WAN)
 May be either client-server or peer-to-peer systems

General Structure of Client-Server 84


6. Real-time OS.:

 Often used as a control device in a dedicated


application such as controlling scientific experiments,
medical imaging systems, industrial control systems,
and some display systems.
 Well-defined fixed-time constraints.
Ex: Scientific experiments, home appliances
 Real-Time systems may be either hard or soft real-
time

85
6. Real-time OS.:
 Real-Time systems may be either hard or soft real-time
 Hard real-time:
 Secondary storage limited or absent, data stored in short term
memory, or read-only memory (ROM)
 Conflicts with time-sharing systems, not supported by general-
purpose operating systems.
 Time constraints can be not be relaxed.
 Soft real-time
 Limited utility in industrial control of robotics
 Useful in applications (multimedia, virtual reality) requiring
advanced operating-system features.
 Time constraints can be relaxed.

86
Classes of OS - Summary

Vishal
87
Kaushal
What have we seen so far?
• What is OS?
– Resource manager and control program
• Basic functions of OS
• OS Services
• OS-User Interface
• System calls
• Types of OS

Vishal
88
Kaushal
OS Structures
 Monolithic
 Layered
 Ringed
 Virtual Machines
 Exo kernels
 Client Server Systems and Microkernels
OS Structure
The OS (a simplified view)

Command Interpreter

Information Services

Error Handling Accounting System


File System

Protection System

Memory Secondary Storage


Process Management Management Management

I/O System

Hardware

92
OS Structure
• An OS consists of all of these components, plus lots of
others, plus system service routines, plus system programs
(privileged and non-privileged), plus ....
• The big issue:
• how do we organize all of this?
• what are the entities and where do they exist?
• how does these entities cooperate?
• Basically, how do we build a complex system that’s:
• performance
• reliable
• extensible

93
Monolithic system
• “The Big mess”
– Every component contained in kernel
• direct communication among all elements
• highly efficient
• Traditionally, systems such as Unix were built as a monolithic
kernel:
user programs

file system, virtual memory,


I/O drivers, process control,
OS kernel everything system services, swapping,
networks, protection,
interrupt handling,
windows, accounting, ...

hardware

94
Monolithic system
• Monolithic Systems
– Entire OS runs as a single program in kernel mode
– Examples: UNIX, LINUX, DOS, Windows 9x

System
call/procedure

Fetch data from


user prog.

95
Monolithic system
• Problems with monolithic kernels:
• hard to understand
• hard to modify
• unreliable: a bug anywhere causes a system crash
• hard to maintain
• Since the beginnings of OS design, people have
wanted ways to organize the OS to simplify its
design and construction.

96
Layered system
• Layered Systems
– Generalization of previous approach
– OS constructed as hierarchy of layers
– The first description of this approach was Dijkstra’s THE system.
– Layers in THE system

97
Layered system
• Problems with Layering
• Systems must be hierarchical, but real systems are
more complex than that, e.g.,
• file system would like to be a process layered on VM
• VM would like to use files for its backing store I/O
• Approach is not flexible.
• Often has poor performance due to layer crossings.
• Systems are often modelled as layered structures
but not built that way (for better or worse).

99
Ringed Approach
 Further generalization of layering concept
 First example: MULTICS
 Series of concentric rings with inner ones more privileged
than outer ones
 Layering scheme of THE was only a design aid
 Everything was ultimately linked into one single object at
runtime
 Ring structure of MULTICS however was very much present
at run time and enforced by hardware
Virtual Machines
OS/360 -> batch system->time sharing
First example: VM/370
Virtual machine monitor runs on bare hardware and does
multi programming providing several virtual machines to next
layer up
These virtual machines are exact copies of bare hardware
Can run any OS .
Virtual Machines
CMS: Conversational Monitor System
Uses
Different Oss can now serve different specific purposes
Running old MS-DOS programs (16 bit) on 32 bit or 64 bit
Windows
Running Java Programs in JVM

Structure of VM/370 with CMS


Virtual Machines
• A virtual machine takes the layered approach to its logical
conclusion.
• It treats hardware and the operating system kernel as though
they were all hardware.
• The operating system host creates the illusion that a process
has its own processor and (virtual memory).
• A virtual machine provides an interface identical to the
underlying bare hardware.
• Each guest provided with a (virtual) copy of underlying
computer.

103
Virtual Machines (Cont.)

(a) Nonvirtual machine (b) virtual machine

104
Exo kernels

VM/360 ,each user process gets exact copy of the actual


computer.
In Exokernels, Clone of the actual computer

Machine is partitioned

Each user is given a subset of resources used by virtual

machines
Exokernel runs in the bottom most layer allocating

resources to VMs

105
Exo Kernels
Client Server Model
Move OS code up into higher layers removing as much as
possible from kernel mode microkernel
User processes are now called client processes
They send requests to server processes (OS running in
user space) which in turn use the services of micro kernel
in kernel mode
OS broken up into several server processes like fileserver,
memory server etc. and a micro kernel
Pure microkernel design is commercially impractical
because it's too inefficient
Too much message passing
Client Server Model

Handles comm.
b/n client & server
Client Server Model
 Each part of OS becomes small and manageable
 Bug in file server will not bring the whole machine down
 Advantage: Adaptability to use in distributed systems

Client server model in a distributed system


Microkernel
• Moves as much from the kernel into “user” space.
• Communication takes place between user modules using message
passing
• First microkernel system was Hydra (CMU, 1970)
• Examples of microkernel systems are the CMU Mach system,
Chorus (French Unix-like system), and in some ways Microsoft
NT/Windows.
• Benefits:
– Easier to extend a microkernel
– Easier to port the operating system to new architectures
– More reliable (less code is running in kernel mode)
– More secure
• Limitation:
– Performance overhead of user space to kernel space
communication
110
Microkernel
user processes

user mode

file system high-level


scheduling
system processes
thread external network
system paging support

communication
microkernel low-level processor kernel mode
VM protection
control

hardware

Microkernel System Structure


111
Monolithic vs Microkernel

112
Microkernel
Windows 2000

“Operating Systems”: Stalling William

115
History of Windows
• Windows
– From 85 to 95, just a graphical environment over MS-DOS
– 4000 lines of AL code, 8KB memory, 8086 microprocessor
– Windows 95, used MS-DOS only for booting and running legacy
MS-DOS programs
– Windows 98
• Windows 95 and 98 still contained large amount of 16-bit AL
• In parallel, MS developed Windows NT
– Full 32 bit system
– Didn’t succeed much
– Became accepted only with v 4.0
• Shell changed from Program Manager to Windows Explorer

Vishal
116
Kaushal
History of Windows
• v 5 of Win NT was renamed Win 2000 in early 1999
– Intended to be a successor of both Win NT 4.0 and Win 98
– Didn’t work as planned, came out with another version of Win 98
and named it Windows Me
• Better version of Win 2000 was released as Win XP
– Had a much longer run: 6 years from 2001
– Replaced all previous versions of Windows
– 64 bit versions started with Win XP onwards

Vishal
117
Kaushal
History of Windows
• Jan 2007: Windows Vista
– Intended as successor to Windows XP
– New graphical interface called Aero
– NT 6.0
• Windows 7: latter half of 2009
– NT 6.1
• Windows 8
– Touch screen friendly
– NT 6.2

Vishal
118
Kaushal
History of Windows

08/06/11 119
Windows 2000 or Win2K

Vishal
120
Kaushal
Design Goals

• Extensibility
– The code must be written to comfortably grow and change as
market requirements change.
• Portability
– The system must be able to run on multiple hardware architectures
and must be able to move with relative ease to new ones as market
demands dictate.
• Reliability and robustness
– The system should protect itself from both internal malfunction and
external tampering
– Applications should not be able to harm the operating system or
other applications.

Vishal
122
Kaushal
Design Goals
• Compatibility
– Although Windows NT should extend existing technology, its
user interface and APIs should be compatible with older
versions of Windows and with MS-DOS
– It should also interoperate well with other systems such as
UNIX, OS/2, and NetWare.
• Performance
– Within the constraints of the other design goals, the system
should be as fast and responsive as possible on each hardware
platform

Vishal
123
Kaushal
Windows 2000 Architecture

124
Windows 2000 Simplified
Architecture

Environment
System & Service Subsystems
Processes User Apps
OS/2 POSIX
Subsystem DLL
Win32

User
Kernel

Executive
Win32
Device
Kernel User/GDI
Drivers
Hardware Abstraction Layer (HAL)

125
Windows 2000 Architecture

 Windows 2000 is a highly modular system that consists of


two main layers: a user mode and a kernel mode
User mode in Windows 2000 is made of subsystems
capable of passing I/O requests to the appropriate kernel
mode drivers by using the I/O manager.
User mode layer of Windows 2000:
 Environment subsystem applications,
 Service processes,
 System support processes

126
User mode
 Special system support processes:
- Include services not provided as part of the Windows
OS, such as logon process, session manager, service
manager, authentication subsystem
• Service processes
– These host Windows services, such as the Task Scheduler
and Spooler services
– Services generally have the requirement that they run
independently of user logons
– Many Windows server applications, such as Microsoft SQL
Server and Microsoft Exchange Server, also include
components that run as services

127
User Mode Processes
• User Applications
– Can be one of six types: Windows 32-bit, Windows 64-bit,
Windows 3.1 16-bit, MS-DOS 16-bit, POSIX 32-bit, or
OS/2 32-bit
• Environment subsystem
– Implement part of the support for the operating system
environment
• personality presented to the user and programmer
– Win NT originally shipped with  Windows, POSIX, and
OS/2
– OS/2 was dropped from Win2K
– Windows XP: only the Windows subsystem is shipped in
the base product
Vishal
• an enhanced POSIX subsystem is available as part of
128
Kaushal
the free Services for Unix product
Environment Sub Systems
• Win32 subsystem runs 32-bit Windows applications and
also supports Virtual DOS Machines (VDMs) , which
allows MS-DOS and 16-bit Windows 3.1x (Win16)
applications to run on Windows.
• OS/2 environment subsystem supports 16-bit character-
based OS/2 applications and emulates OS/2 1.3 and
1.x, but not 32-bit or graphical OS/2 applications as used
on OS/2 2.x or later.
• POSIX environment subsystem supports applications
that are strictly written to either the POSIX.1 standard or
the related ISO IEC standards

Vishal
129
Kaushal
User Mode Processes
• Subsystem DLLs
– User applications don't call the native Windows
operating system services directly; rather, they go
through these
– Translate a documented function into the appropriate
internal (and generally undocumented) Windows
system service calls

Vishal
130
Kaushal
Windows 2000 Architecture
Kernel mode
• Kernel mode in Windows 2000 has full access to the
hardware and system resources of the computer.
•The kernel mode stops user mode services and
applications from accessing critical areas of the operating
system that they should not have access to.
•The executive interfaces with all the user mode
subsystems. It deals with I/O, object management, security
and process management

131
Executive Modules
• Process and thread manager
– handles process and thread creation and termination
• Virtual memory manager
– manages virtual memory, allowing Windows 2000 to use the hard disk as a
primary storage device (although strictly speaking it is secondary storage).
• I/O system
– allows devices to communicate with user-mode subsystems by translating
user-mode read and write commands and passing them to device drivers.
• Cache manager
– Improves the performance of files based I/O by causing recently
referenced disk data to reside in main memory for quick access.
• Object manager
– create, manage, destroy windows executable Objects
– A special executive subsystem that all other executive subsystems must
pass through to gain access to Windows 2000 resources.
– This is essentially a resource management infrastructure Vishalservice that
132
Kaushal
allows Windows 2000 to be an object oriented operating system.
Executive Modules
• LPC (Local Procedure call) facility
– flexible, optimized version of RPC,
– Enforces a client-server relationship between applications and
executives subsystems.
• PnP Manager
– handles Plug and Play and supports device detection and
installation at boot time
• Power Manager
– It coordinates power management among various devices and
reduce power consumption.
• Configuration manager
– Responsible for implementing and managing the system registry.
• Security reference monitor
– protection/auditing

Vishal
133
Kaushal
Kernel

 Most used and fundamental component of OS


 Thread scheduling and dispatching

 Trap handling and exception dispatching

 Interrupt handling and dispatching

 Multiprocessor synchronization

 Base kernel objects for executive


 Never paged out of memory/nonpreemptable

134
Device Drivers
 Loadable kernel modules

 Don‘t manipulate hardware, but call parts of HAL

 Written in C/C++ typically

 Source code portable across CPU architectures !!

Types:

 Hardware device drivers: implement device/network I/O

 File system drivers: file I/O <-> device I/O

 Filter drivers: disk mirroring, encryption

 Network redirectors and servers: send/receive remote I/O requests

135
Kernel Mode Processes
• Windowing and graphics system
– implements the graphical user interface (GUI) functions
– Eg. dealing with windows, user interface controls, and
drawing

Vishal
136
Kaushal
Hardware Abstraction Layer

 The Windows 2000 Hardware Abstraction Layer, or HAL, is


a layer between the physical hardware of the computer and
the rest of the operating system.
 It was designed to hide differences in hardware and
therefore provide a consistent platform to run applications on.
 The HAL includes hardware specific code that controls I/O
interfaces, interrupt controllers and multiple processors
Eg. differences between motherboards

137
Hardware Abstraction Layer
The HAL provides the following services:
 Integration with the newlib ANSI C standard library-
- Provides the familiar C standard library functions

 Device drivers —Provides access to each device in the system

 The HAL API —Provides a consistent, standard interface to HAL services,


such as device access, interrupt handling, and alarm facilities

 System initialization —Performs initialization tasks for the processor and the
runtime environment before main()

 Device initialization —Instantiates and initializes each device in the system


before main() runs

138
LINUX

139
Layers of a UNIX System

140
General UNIX Architecture

UNIX Commands and


libraries

System call
interface

Kernel

142
What is Linux
 A fully-networked 32/64-Bit Unix-like Operating System
Unix Tools Like sed, awk, and grep (explained later)
Compilers Like C, C++, Fortran, Smalltalk, Ada
Network Tools Like telnet, ftp, ping, traceroute
Multi-user, Multitasking, Multiprocessor
Has the X Windows GUI
Coexists with other Operating Systems
Runs on multiple platforms
Includes the Source Code

143
Where did it come from?(History)

Launched as an upgradation of the Minix Operating System.


Linus Torvalds created it
with assistance from programmers around the world
first posted on Internet in 1991
Linux 1.0 in 1994; 2.2 in 1999
Today used on 7-10 million computers
with 1000’s of programmers working to enhance it

144
History
Linux is on a path of continuous improvement
Linux is being continuously:
Downloaded
Modified
Fine-tuned
The
future

The
past

145
How do you get it?
Download it from the Internet
From a “Distribution” (e.g. RedHat)
Linux kernel
X Windows system and GUI
Web, e-mail, FTP servers
Installation & configuration support
3rd party apps
Hardware support

146
Features of Linux
Free
Compatibility on most hardware
Well documented
Customisable
Open source
Multi-tasking capability
TCP/IP Networking
High level of security
Programming support for many languages
GUI support

147
Linux Architecture
 The Kernel is the heart of the operating system. Its main
functions are:

 Controlling computer resources APPLICATION


 Allotting resources to different user

SHELL

 The user does not directly pass commands to


the Kernel KERNEL

 The Shell handles user interaction with HARDWARE


the system

148
Linux Architecture ( Contd ...)

SHELL

KERNEL TO
KERNEL
HARDWARE
HARDWARE SHELL COMMUNICATION
SHELL

KERNEL TO SHELL
COMMUNICATION
SHELL

Tools and
Application
149
Directory Hierarchy

ROOT DIRECTORY

BIN TMP
SBIN
BOOT
ROOT
DEV
ETC HOME PROC USR
MOUNT

KEVIN
SUSAN
DHAR
DYLAN

ASSET
APTECH MICKEY
LIN1

150
Vishal
151
Kaushal
Vishal
152
Kaushal
Modular structure
 Although monolithic, the kernel is structures as a collection of
modules
 Linux is structured as a collection of modules, a number of which can
be automatically loaded and unloaded on demand.
 These relatively independent blocks are referred to as loadable
modules.
 Module is an object file whose code can be linked to and unlinked
from the kernel at runtime.
It implements specific function such as file system, device drivers
 It is not a separate process/thread.
 It is executed in kernel mode on behalf of the current process.

153
Modular Structure

The Linux loadable modules have two important characteristics:


Dynamic linking: A kernel module can be loaded and linked into the
kernel while the kernel is already in memory and executing.
A module can also be unlinked and removed from memory at any time.
Saves kernel memory.

Stackable modules: The modules are arranged in a hierarchy.


Individual modules serve as libraries when they are referenced by client
modules higher up in the hierarchy, and as clients when they reference
modules further down.

154
Modular Structure
• User can explicitly load module using insmod command.
• unloaded using rmmod command.
• Kernel monitors the need for particular function and can load &
unload modules as needed.
• In stackable modules dependencies b/n modules can be defined.
• Common code b/n set of modules can be moved into a single
module reducing replication.
• Kernel make sure that needed modules are present & avoid
unloading of models.

08/06/11 155
Linux Kernel Modules

156
Linux Kernel Modules
• It shows that the VFAT module was loaded after the FAT
module and that the VFAT module is dependent on the FAT
module.
• Modules are organized as linked list.
• Each module is defined by two tables,
1. Module table
2. Symbol table.

The symbol table defines those symbols controlled by this


module that are used elsewhere.

157
Module Table
• next: Pointer to the following module. All modules are organized into
a linked list.
• name: Pointer to module name
• size: Module size in memory pages
• usecount: Module usage counter. The counter is incremented when
an operation involving the module’s functions is started and
decremented when the operation terminates
• flags: Module flags
• nsyms: Number of exported symbols
• ndeps: Number of referenced modules
• syms: Pointer to this module’s symbol table.
• deps: Pointer to list of modules that are referenced by this module.
• refs: Pointer to list of modules that use this module

Vishal
158
Kaushal
Linux kernel components
 This figure shows the main components of the Linux
kernel as implemented on an IA-64 architecture (e.g.
Intel Itanium).
 It shows several processes running on top of the
kernel.
 Each box indicates a separate process, while each
squiggly line with an arrowhead represents a thread
of execution.

159
Linux kernel components

160
Kernel Components
• Signals: The kernel uses signals to call into a process.
– For example, signals are used to notify a process of
certain faults, such as division by zero.
• System calls: The system call is the means by which a
process requests a specific kernel service. There are
several hundred system calls, which can be roughly
grouped into six categories: file system, process,
scheduling, IPC, socket, and miscellaneous
• Processes and scheduler: Creates, manages, and
schedules processes.
• Virtual memory: Allocates and manages virtual memory
for processes
Vishal
161
Kaushal
Kernel Components
• File systems: Provides a global, hierarchical namespace
for files, directories, and other file related objects and
provides file system functions.
• Network protocols: Supports the Sockets interface to
users for the TCP/IP protocol suite
• Character device drivers: Manages devices that require
the kernel to send or receive data one byte at a time,
such as terminals, modems, and printers.
• Block device drivers: Manages devices that read and
write data in blocks, such as various forms of secondary
memory (magnetic disks, CD-ROMs, etc.)

Vishal
162
Kaushal
Kernel Components

• Network device drivers: Manages network interface


cards and communications ports that connect to network
devices, such as bridges and routers.
• Traps and faults: Handles traps and faults generated by
the processor, such as a memory fault.
• Physical memory: Manages the pool of page frames in
real memory and allocates pages for virtual memory.
• Interrupts: Handles interrupts from peripheral devices

Vishal
163
Kaushal
Do you agree?
• Each processor is doing exactly one of three things at
any given moment:
– In user-space, executing user code in a process
– In kernel-space, in process context, executing on
behalf of a specific process
– In kernel-space, in interrupt context, not associated
with a process, handling an interrupt

Vishal
164
Kaushal
Self Study
•Overview of Linux
•Windows 2000 architecture

Vishal
165
Kaushal

You might also like