Inroductiion To OS

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 78

Introduction

To
Operating Systems

Dr. A. NISHAJEBASHEELI
Assistant Professor
Department of Computer Science
Bharathidasan University, Trichy
What is an Operating System?

 An operating system (OS) is the program that, after being initially

loaded into the computer by a boot program, manages all of the other
application programs in a computer. The application programs make
use of the operating system by making requests for services through a
defined application program interface (API).
Computer System Components

1. Hardware – provides basic computing resources (CPU,


memory, I/O devices).

2. Operating system – controls and coordinates the use of the


hardware among the various application/system programs
for the various users.

3. Applications/system programs – define the ways in which the


system resources are used to solve the computing problems of
the users (compilers, database systems, video games, business
programs).

4. Users (people, machines, other computers).


Abstract View of System Components
Operating System Definitions

 Resource allocator – manages and allocates resources.


 Control program – controls the execution of user
programs and operations of I/O devices and handles
errors
 Kernel – the one program running at all times (all else
being application programs).
Computer startup

 bootstrap program is loaded at power-up or reboot


 Typically stored in ROM or EEPROM, generally known as
firmware
 Initializates all aspects of system
 Loads operating system kernel and starts execution
Mainframe Systems
 A mainframe operating system is software that manages the resources

and activities of large, and powerful mainframe computers. The


mainframe operating system is designed so that it can handle multiple
jobs simultaneously. To deal with large amounts of transactions is one
of their features which is why they are used by large organizations
such as banks, and governments.
 For example, IBM z/OS, and IBM z/VSE.
Services provided by Main Frame
 They perform operations like clustering and partitioning.

 They act as the base for extensive applications.

 It divides the jobs into different batches.

 It provides data security and efficient task management.

 It performs a large amount of transactions.


Memory Layout for a Simple Batch System
Multiprogrammed Batch Systems
Several jobs are kept in main memory at the same time, and the CPU
is multiplexed among them.

Initially used punched cards 


data ,
program and control cards

Spooling (simultaneous peripheral operation


online ) Introduction of disk technology
So cards can be read into disk for later cpu
reading & cpu o/p for printing can also be put
on disk for later printing
So spooling can help overlap the i/o of
one job with the computation of the other.
OS Features Needed for Multiprogramming

 I/O routine supplied by the system.


 Memory management – the system must allocate the
memory to several jobs.
 Job scheduling : choosing a job from many ready jobs on
disk to bring it to the memory
 CPU scheduling – the system must choose among
several jobs ready to run.
 Allocation of devices.
Time-Sharing Systems–Interactive Computing

 The CPU is multiplexed among several jobs that are kept in


memory (the CPU is allocated to a job only if the job is in
memory).
 A job can be swapped in and out of memory from/to the
disk.
 With time sharing systems -- the interactive systems
were possible. Each process was given small quantum of time
Multiprogramming/multitasking
 Multiprogramming needed for efficiency
 Single user cannot keep CPU and I/O devices busy at all times

 Multiprogramming organizes jobs (code and data) so CPU always has one to

execute
 A subset of total jobs in system is kept in memory

 One job selected and run via job scheduling

 When it has to wait (for I/O for example), OS switches to another job

 Timesharing (multitasking) is 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
Desktop Systems

 Personal computers – computer system dedicated to a


single user.
 I/O devices – keyboards, mice, display screens, small
printers.
 User convenience and responsiveness.
 Can adopt technology developed for larger operating system’
often individuals have sole use of computer and do not need
advanced CPU utilization of protection features.
 May run several different types of operating systems
(Windows, MacOS, UNIX, Linux)
Parallel Systems

 Multiprocessor systems with more than one CPU in close


communication.
 Tightly coupled system – processors share memory and a
clock; communication usually takes place through the shared
memory.
 Advantages of parallel system:
 Increased throughput :: as more processors so more work
done per unit time but increase is not n (for n
processors) as some time will be wasted in overheads and
contention for shared resources.
 Economical
 Increased reliability
 graceful degradation  fault tolerance
Parallel Systems (Cont.)

 Symmetric multiprocessing (SMP)


 Each processor runs and identical copy of the operating system
and these can be communicated ( through shared memory as &
when needed)
 Many processes can run at once without performance
 deterioration.
 Most modern operating systems support SMP
 Asymmetric multiprocessing
 Each processor is assigned a specific task; master
processor schedules and allocated work to slave
processors.
 More common in extremely large systems
Multiprocessing Architecture
Distributed Systems

 Distribute the computation among several physical


processors.
 Loosely coupled system – each processor has its own local
memory; processors communicate with one another through
various communications lines, such as high- speed buses or
telephone lines.
 Advantages of distributed systems.
 Resources Sharing
 Computation speed up – load sharing
 Reliability
 Communications (ie exchange of information in form of mail,
file transfer is possible)
Distributed Systems (cont)
 Requires networking infrastructure.
 Local area networks (LAN) or Wide area networks (WAN)
 May be either client-server or peer-to-peer systems.
General Structure of Client-Server
Real-Time Systems
 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.
 Real-Time systems may be either hard or soft real-time.
Real-Time Systems (Cont.)

 Hard real-time:
• Secondary storage limited or absent, data stored in short
term memory, or read-only memory (ROM)
• Conflicts with time-sharing systems as no virtual memory.

 Soft real-time
• Limited utility in industrial control of robotics
• Useful in applications (multimedia, virtual reality, undersea
exploration, planetory rovers) requiring advanced
operating- system features.
• Ex. RT Linux
Computer-System Architecture

Bootstrap:(1) Initialize h/w - like cpu registers, device controllers, memory controllers etc ( 2 )
Loads o.s kernel into the primary memory and then transfers control to O.S
Computer-System Operation

 I/O devices and the CPU can execute concurrently.


 Each device controller is in charge of a particular device
type.
 Each device controller has a local buffer & a set of special
purpose registers
 CPU loads the appropriate registers with in the device
controller ( say for some read operation )
 I/O is from the device to local buffer of controller.
 CPU moves data from/to main memory to/from local
buffers
 Device controller informs CPU that it has finished its
operation by causing an interrupt.
Common Functions of Interrupts

 Interrupt transfers control to the interrupt service routine


generally, through the interrupt vector, which contains the
addresses of all the service routines.
 Interrupt architecture must save the address of the
interrupted instruction.
 Incoming interrupts are disabled while another interrupt is
being processed to prevent a lost interrupt (specifically when
program counters and other registers are being saved )
 A trap is a software-generated interrupt caused either by
an error or a user request.
 An operating system is interrupt driven.
Interrupt Handling

 The operating system preserves the state of the CPU by storing


registers and the program counter. (disable further interrupts,
while this is being done )
 Separate segments of code determine what action should
be taken for each type of interrupt
I/O Structure
 After I/O starts, control returns to user program only upon I/O
completion.  Synchronous I/O
 Wait instruction idles the CPU until the next interrupt
 Wait loop (contention for memory access). infinite loop
 Such infinite loop might also need to pool any i/o device
that do not support interrupt structure
 POOLING :: check for a flag (in i/o device controller) to
become true or false
 At most one I/O request is outstanding at a time, no
simultaneous I/O processing.
 After I/O starts, control returns to user program without
waiting for I/O completion.  Asynchronous I/O
 When i/o completes, the I/O device controller interrupts the
CPU to inform the CPU that it has finished it’s operation
Two I/O Methods

Synchronous Asynchronous
Device-Status Table

First element in the queue : represents the request being processed


Other elements in the queue : represents the requests waiting in the
queue
Contd…

 When i/o needs CPU attention (because it wants to start new


operation or it has completed an operation), it interrupts
 The O.S in response to the interrupt, first determines which i/o
device raised the interrupt and then indexes into the i/o device
table accordingly
 O.s now modifies the device table entry and status
accordingly (if i/o completed – also inform the waiting
process accordingly )
Direct Memory Access Structure(DMA)

 Used for high-speed I/O devices able to transmit


information at close to memory speeds.
 Device controller transfers blocks of data from buffer
storage directly to main memory without CPU
intervention.
 Only one interrupt is generated per block, rather than the
one interrupt per byte.
Storage Structure
 Main memory – only large storage media that the CPU
can access directly.
 Secondary storage – extension of main memory that
provides large nonvolatile storage capacity.
 Magnetic disks – rigid metal or glass platters covered with
magnetic recording material
 Disk surface is logically divided into tracks, which are
subdivided into sectors.
 The disk controller determines the logical interaction
between the device and the computer.
Moving-Head Disk Mechanism
Magentic Tape

 Slow
 Good for sequential access and not good for random
access
 Generally used as Backup media
Storage Hierarchy
 Storage systems organized in hierarchy.
 Speed
 Cost
 Volatility

 Caching – copying information into faster storage system;


main memory can be viewed as a last cache for secondary
storage.

 Main memory  generally dynamic RAM, cache  static


RAM

 The program must be in main memory to be executed


because main memory is the only large storage area (in
addition to registers and cache) that the processor can access
directly
Storage-Device Hierarchy

As we go down the level : access time increases,


cost per bit decreases, block size increases
Magnetic disk and below : non volatile Electronic
disk :nothing but large DRAM ARRAY
Caching

 Use of high-speed memory to hold recently-accessed


data.
 Requires a cache management policy.
 Caching introduces another level in storage hierarchy. This
requires data that is simultaneously stored in more than one
level to be consistent.
 CACHE COHERENCE & CONSISTENCY
 uniprocessors systems : not a big problem
 multiprocessor systems : big problem
 cache coherence is generally a h/w issue and is
handled below the O. S. level
Migration of A From Disk to Register
Hardware Protection

 Dual-Mode Operation
 I/O Protection
 Memory Protection
 CPU Protection
Dual-Mode Operation

 Sharing system resources requires operating system to ensure that an


incorrect program cannot cause other programs to execute incorrectly.
(basically provides us with the means for protecting the O. S from
errant users, and errant users from one another

 Provide hardware support to differentiate between at least two


modes of operations.
1. User mode – execution done on behalf of a user.
2. Monitor mode (also kernel mode or system mode) – execution
done on behalf of operating system.
 Certain instruction can only be run in monitor mode
 At system boot time, the h/w starts in monitor mode.
The o.s is then loaded and starts user processes in user mode
Dual-Mode Operation (Cont.)

 Mode bit added to computer hardware to indicate the


current mode: monitor (0) or user (1).
 When an interrupt or fault occurs hardware
switches to
monitor mode.
Interrupt/fault/trap

monitor user
set user mode

Privileged instructions can be issued only in monitor mode.


I/O Protection

 A user program may disrupt the normal operation of the


system by issuing illegal I/O instruction, by accessing
memory location within the O.S itself or by refusing to
relinquish the CPU
 To prevent users from doing illegal I/O, All I/O instructions
are privileged instructions.
 Must ensure that a user program could never gain control of
the computer in monitor mode (I.e., a user program that, as
part of its execution, stores a new address in the interrupt
vector).
Use of A System Call to Perform I/O
Memory Protection

 Must provide memory protection at least for the interrupt


vector and the interrupt service routines. (so that an errant
user does not get the power to work in protected mode)
Interrupt vector

Table (in Mem) User Program -trap to


SAR4  Take address from
Service routine
address 1
IVT & execute the service
Service routine (this is required to be
SRA 2 Routine done in monitor mode)
SRA 3 If user modifies SAR4
address and gives there the
SRA 4 Memo address of his program then
ry he can run his program in
monitor mode
Contd ..

 In order to have memory protection, add two registers that


determine the range of legal addresses a program may
access: (to protect errant users from each other)
 Base register – holds the smallest legal physical memory
address.
 Limit register – contains the size of the range
 Memory outside the defined range is protected.
Use of A Base and Limit Register
Hardware Address Protection
300040 300040 +120900 = 420940
Hardware Protection

 When executing in monitor mode, the operating system has


unrestricted access to both monitor and user’s memory.
 The load instructions for the base and limit registers are
privileged instructions.
CPU Protection

 O.S should ensure that a process is not stuck up in


an
infinite loop and so will held the CPU for ever.
 Soln.
 Timer – interrupts computer after specified period to
ensure operating system maintains control.
 Timer is decremented every clock tick.
 When timer reaches the value 0, an interrupt occurs.
 Timer commonly used to implement time sharing.
 Time also used to compute the current time.
 Load-timer is a privileged instruction.
Process Management

 A process is a program in execution. A process needs


certain resources, including CPU time, memory, files, and I/O
devices, to accomplish its task.
 The operating system is responsible for the following
activities in connection with process management.
 Process creation and deletion.
 process suspension and resumption.
 Provision of mechanisms for:
 process synchronization
 process communication
Main-Memory Management

 Memory is a large array of words or bytes, each with its own


address. It is a repository of quickly accessible data
shared by the CPU and I/O devices.
 Main memory is a volatile storage device. It loses its
contents in the case of system/power failure.
 The operating system is responsible for the following
activities in connections with memory management:
 Keep track of which parts of memory are currently being
used and by whom.
 Decide which processes to load when memory space
becomes available.
 Allocate and deallocate memory space as needed.
File Management

 A file is a collection of related information defined by its


creator. Commonly, files represent programs (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 (nonvolatile) storage media.
I/O System Management

 The I/O system consists of:


 A buffer-caching system
 A general device-driver interface
 Drivers for specific hardware devices
Secondary-Storage Management

 Since main memory (primary storage) is volatile and too


small to accommodate all data and programs permanently,
the computer system must provide secondary storage to
back up main memory.
 Most modern computer systems use disks as the principle on-
line storage medium, for both programs and data.
 The operating system is responsible for the following
activities in connection with disk management:
 Free space management
 Storage allocation
 Disk scheduling
Networking (Distributed Systems)
 A distributed system is a collection processors that do not
share memory or a clock. Each processor has its own
local memory.
 The processors in the system are connected through a
communication network.
 Communication takes place using some protocol.
 A distributed system provides user access to various
system resources.
 Access to a shared resource allows:
 Computation speed-up
 Increased data availability
 Enhanced reliability
NOTE : O.S usually generalize network access as a form of a file
access, with the details of networking being contained in the
network interfaces device driver
So the objective is to hide the details of getting information from
other system and to make such access as efficient as possible.
Protection System

 Protection refers to a mechanism for controlling access by


programs, processes, or users to both system and user
resources.
 The protection mechanism must:
 distinguish between authorized and unauthorized usage.
 specify the controls to be imposed. POLICY
 provide a means of enforcement.
Command-Interpreter System

 The program that reads and interprets control


statements/commands is called variously:

 command-line interpreter
 shell (in UNIX)

Its function is to get and execute the next command


statement.
 Command interpreter can be GUI based
(windows/macintosh) or text based (like UNIX Shell)
Command-Interpreter System

 Many type of commands are given to the operating


system like
 process creation and management related commands
 I/O handling
 secondary-storage management
 main-memory management
 file-system access
 protection
 networking
Operating System Services
 An O.S provides an environment for execution of the program
 The O.S provides certain services to program and users of those
programs for efficiency and convenience to the programmers
 Program execution – system capability to load a program into
memory , to run it, terminate program normally or abnormally
 I/O operations – since user programs cannot execute I/O
operations directly, the operating system must provide some
means to perform I/O.
 File-system manipulation – program capability to read, write,
create, and delete files.
 Communications – exchange of information between processes
executing either on the same computer or on different systems tied
together by a network. Implemented via shared memory or
message passing.
 Error detection – ensure correct computing by detecting errors in the
CPU and memory hardware, in I/O devices, or in user programs.
Additional Operating System Functions

Additional functions exist not for helping the user, but rather
for ensuring efficient system operations.
• Resource allocation – allocating resources to multiple users
or multiple jobs running at the same time.
• Accounting – keep track of and record which users use how
much and what kinds of computer resources for account billing
or for accumulating usage statistics.
• Protection – ensuring that all access to system resources is
controlled.
System Calls

 System calls provide the interface between a running


program (Process) and the operating system.
 Generally available as assembly-language , C or C++
instructions.
 Three general methods are used to pass parameters
between a running program and the operating system.
 Pass parameters in registers.
 Store the parameters in a table in memory, and the table
address is passed as a parameter in a register.
 Push (store) the parameters onto the stack by the program,
and pop off the stack by operating system.
API – System Call – OS Relationship
Types of System Calls

 Process control (end, abort, load program into memory, execute,


create, get/set process attributes( attributes like job’s priority &
max. allowed execution time ), wait (wait for a child process to
return/end for certain time), wait for event, signal event, allocate &
free memory
 File management  create file, delete file, open, close, read,
write
 Device management  Request device, release device, read,
write etc
 Information maintenance get/set time of day, get/set system
data etc
 Communications  shared memory or message passing
create/delete communication connection, send/
receive messages etc
MS-DOS Execution
( is a single tasking O.S)

At System Start-up Running a Program


MS-DOS shows the limited capability of multitasking/concurrency
with the help of TSRs (terminal & stay resident system calls)
UNIX Running Multiple Programs

Note: UNIX process related system calls  fork, exec, exit (return
with error code 0 (no error), any positive no (error no)
Communication Models
 Communication may take place using either message
passing or shared memory.

Msg Passing Shared Memory


System Programs

 System Programs  are basically user interface to the system calls and
in some case they can be quite complex (like command is a system
program)
 System programs provide a convenient environment for program
development and execution. The can be divided into:
 File manipulation
 Status information
 File modification
 Programming language support
 Program loading and execution
 Communications
 Application programs
Example of system programs  create, copy, delete, rename, remote
login, send, receive etc text editors, compilers, loaders, linkers etc
 Internal Commands ?
 External Commands ?
MS-DOS Layer Structure
MS-DOS System Structure

 MS-DOS – written to provide the most functionality in the


least space
 not divided into modules
 Although MS-DOS has some structure, its interfaces and
levels of functionality are not well separated (for instance
application programs are able to access the basic I/O routines
directly, this makes the MS-DOS vulnerable to errant
(malicious) programs
 Why so in DOS was built for 8085 and 8086 didn't support
DUAL mode of operation
UNIX System Structure

 UNIX – limited by hardware functionality, the original UNIX


operating system had limited structuring. The
UNIX OS consists of two separable parts.
 Systems programs
 The kernel
 Consists of everything below the system-call interface
and above the physical hardware
 Provides the file system, CPU scheduling, memory
management, and other operating-system functions; a large
number of functions for one level.
UNIX System Structure
Layered Approach

 The operating system is divided into a number of layers (levels), each


built on top of lower layers. The bottom layer (layer 0), is the
hardware; the highest (layer N) is the user interface.
 Advantage :: modularity  layers are selected such that each uses
functions (operations) and services of only lower-level layers. ( The
design & implementation of the system is simplified when the system
is broken down into layers )
 Layer M – 1 consists of some data structure & a set of routines that
can be invoked by higher level layer. Layer M – 1, in return can
invoke operation on lower level layers
 Layer is an abstract object that is the encapsulation of data and
operations that can manipulate those data
An Operating System Layer
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.
 A virtual machine provides an interface identical to the
underlying bare hardware.
 The operating system creates the illusion of multiple
processes, each executing on its own processor with its own
(virtual) memory.
Virtual Machines (Cont.)

 The resources of the physical computer are shared to


create the virtual machines.
 CPU scheduling can create the appearance that users have
their own processor.
 Spooling and a file system can provide virtual card readers
and virtual line printers.
 A normal user time-sharing terminal serves as the virtual
machine operator’s console.
System Models

Non-virtual Machine Virtual Machine


Advantages/Disadvantages of Virtual Machines

 The virtual-machine concept provides complete protection of


system resources since each virtual machine is isolated from
all other virtual machines.
This isolation, however, permits no direct sharing of resources.
 A virtual-machine system is a perfect vehicle for operating-
systems research and development. System
development is done on the virtual machine, instead of on a
physical machine and so does not disrupt normal system
operation.
 The virtual machine concept is difficult to implement due to
the effort required to provide an exact duplicate to the
underlying machine.
THANK YOU

You might also like