Вы находитесь на странице: 1из 105

Operating

Systems

Operating Systems

Topics to discuss

What is an operating system(OS)?

Main objectives of an OS

Main functions of an OS

Evolution of OS.

Process management.

Context switching.

Process state diagrams

Components of a Computer System

hardwareelectronic, mechanical, optical

devices.

softwareprograms.

Liveware Computer Users

What is an operating

system(OS)?

 

An operating system (OS) is a resource manager.

 

What is the necessity for a resource manager?

 

 

Many processes are active at any given time and

compete for resources.

An operating system provides orderly and controlled allocation of the resources among processes (jobs) that are competing for them.

Different types of Software

Application Software

Systems Software

Operating system System utilities

The quality of system software also directly

affects the application software

Types of Software

Utility software: system software designed to help analyze, configure, optimize

Transient Component
Transient Component

or maintain a computer(Anti -

virus, Backup software, Editors, Data compression, Disk cleaners ….). They are not essential to the running of the computer

Execution of source programs

Execution of source programs Operating Systems 7

What is an operating

system(OS)?

What is an operating system(OS)? Operating Systems 8

What is an operating

system(OS)?

Kernel : Part of the O/S that resides in the main memory all the time.
Kernel : Part of the
O/S that resides in
the main memory
all the time.

Different types of OSs(Based

on the processor)

Windows/Linux For personal computers

Unix,z/OS, OS/390, VM For mainframes

MacOs For Macs

X Server, Windows Server Server Operating Systems

Symbian,Android For mobile phones.

Different types of

OSs(Based on the users)

Single User Allows only a single user to use

the OS at any given time. The use may run several processes at the same time.

Example - DOS

Multi User - Allows multiple users to access

a computer system at the same time Example UNIX, Time-sharing systems and Internet

servers.

Different types of OSs(Based

on the number of tasks)

Single TaskAllows only one running program

at any given time.

Multi Task - A multi-tasking operating system allows more than one program to be running

at the same time.

Different types of OSs

Real Time OS is designed to run applications

with very precise timing and with a high degree of reliability.

The main objective of real-time operating systems is their quick and predictable response to events.

These types of OS are needed in situations where downtime is costly or a program delay could cause a safety hazard.

Main objectives of an OS

Convenience: Make the computer more convenient to use

Provide easy to use interface for a normal users.

Hide the complexity of the hardware devices from the application developer.

Efficiency: Monitor and manage resources of the computer system efficiently

CPU

Main memory

Secondary Storages

Various devices connected to the computer

Services provided by an

OS

Process Management Storage (external) management Memory management I/O device management Management of the File System Networking User Interface Protection

Services provided by an OS….

Error detection and response

Hardware errors: memory error or device failure

Software errors: arithmetic errors, access forbidden memory locations

Accounting

collect statistics (billing)

monitor performance

Types of User Interfaces

Command Line Interface(CLI)

Types of User Interfaces Command Line Interface(CLI) Operating Systems 17

Types of User Interfaces

Graphical User Interface(GUI)

OS and Processors

Can any OS run on any processor? Operating systems are software Operating systems are designed
Can any OS run on any
processor?
Operating systems are software
Operating systems are designed
and developed for a specific
CPU family.
◦ Macintosh OS: Motorola
680xx, PowerPC Gx, Intel
◦ DOS: Intel CPUs
◦ Windows 9x and XP: Intel 80386,
80486, and Pentium CPUs
◦ Linux: Intel CPUs
◦ MS NT & 2000: Intel CPUs

Compatibility of Software

Question

Will software developed for one operating system work on another?

For example will MS Word for Macintosh run on a PC with Windows XP?

Compatibility of Software

Question

Will software developed for one operating

system work on another?

Answer

No (unless there is special emulation software or hardware). The software is typically

developed separately for each operating system.

Evolution of Operating systems

Serial Processing (1940 – mid 1950s) ◦ Single user system. ◦ Programmer/User acts as the
Serial Processing (1940 –
mid 1950s)
◦ Single user system.
◦ Programmer/User acts as the
operator and interacted with
the hardware.
◦ No operating system.
◦ Machines run from a console
with display lights, toggle
switches.

Paper Tapes or Punched cards for the program and I/O.

Setup included loading the compiler, source program, saving compiled program, and loading and linking

Disadvantages :

 

Scheduling: Hardcopy sigh-up sheet for reserving

time

 

User could reserve for 45 mins and finish in 30 mins

=> wastage of time

User may not be able to finish in scheduled time

Simple batch system

Simple Batch Processing Systems

Use of high-level languages

Jobs are batched together by the

language.

languages ◦ Jobs are batched together by the language. ◦ Input/output is through punch cards and

Input/output is through punch cards and magnetic tapes.

Software called the Monitor was introduced to sequence the jobs.

Hardware support for the monitor model

Memory protection: some memory areas are accessible only to the monitor

Privileged mode instructions: only accessible to the monitor

Interrupts (early machines did not have this)

Simple batch processing

system

The user submits a job (written on cards or tape) to a computer operator.

The computer operator place a batch of several jobs on an input device.

A special program called the monitor, manages the execution of each program in the batch.

“Monitor” is always in main memory.

Monitor reads and loaded programs sequentially and then (the utility programs when needed) passed the control to the loaded program.

When a job terminates the control returns back to the monitor program. Alternate execution between user program and the monitor program.

instructions for the monitor were given by using a special purpose language called Job Control Language (JCL)

Simple batch system …

A user program executes in user mode, in

which certain areas of memory were protected from the user’s use, and user program is not allowed to execute certain instructions.

The monitor executes in a system mode, or a kernel mode and it can execute privileged

instructions and can access protected memory segments.

Machine time alternates between

monitor and the user programs.

Simple batch system …

Disadvantages

A portion of the memory has to be allocated for the monitor A small portion of the machine time is consumed by the monitor.

Advantage of batch systems.

Reduce setup time by batching similar jobs.

Card Deck of a job

Simple batch system :

Problems

During I/O operations CPU is not used.

Simple batch system : Problems ◦ During I/O operations CPU is not used. Operating Systems 28

Simple batch system : I/O

I/O devices (Card Readers, Printers) slow when compared to CPU.

Solution: Offline Operation (Satellite Computers)

Speed up computation by loading jobs into memory from

tapes while card reading and line printing is done off-line using smaller machines.

Multiprogramming

Running multiple programs “at the same time”

Requires sharing the CPU among multiple processes

Firefox

Word

javac

Firefox

Word

processes Firefox Word javac Firefox Word Transfer of control is called a context switch Operating

Transfer of control is called a context switch

Multiprogramming

Why multiprogramming? 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 CPU is give for that job.

When it has to wait, OS switches to another job.

Multiprogramming

Multiprogramming Operating Systems 32

Time Sharing Systems

Processor’s time is shared among multiple users

Multiple users simultaneously access the system through terminals.

shared among multiple users • Multiple users simultaneously access the system through terminals. Operating Systems 33

Multiprogramming Vs

Time Sharing Systems

Multiprogramming maximizes CPU utilization

Time-sharing minimizes user response time

Loading the Operating System

OS is also a software like any other, but has to be loaded and run by the OS itself.

The process of initializing the computer and loading the OS is known as bootstrapping or booting the system.

The bootstrapping program normally exist in non- volatile memory and is executed automatically when the machine is turned on.

The operating system software (kernel) copied into RAM, usually from the hard disk, during the boot-up.

Once loaded the OS wait for an event to occur (eg:

user typing a command) and process the event.

OS is an event driven software

Loading the Operating System

The kernel remains in RAM while the computer

is on and is in charge of the overall operation of the computer system.

The kernel contains the “internal programs”

for the most often used operations like file management, memory management, security.

Gaining Control

 

The OS gets the control of the CPU when either an

external event or an internal event occurs.

 

External Events

 

 

Character typed at the console

 

 

Completion of an I/O operation

 

 

Timer quantum allowed for a process expires.

 

 

Internal Events

 

 

Division by zero,

 

 

System call issued by a program

 

Page Fault Unauthorized memory access

System call issued by a program      Page Fault  Unauthorized memory access

Operating Systems

37

Interrupts

External events get the attention of the CPU

through Interrupts.

For example when a disk driver has finished transferring the requested data, it generates an

interrupt to the OS to inform the OS that the task

is over.

Interrupts occur asynchronously to the ongoing activity of the processor. Thus the times at which interrupts occur are unpredictable.

Interrupt Handlers

Interrupt Handlers : Code that get executed when

an interrupt occurs.

Associated with each type of interrupt there is a specific program to handle that type of interrupts Interrupt handler (Interrupt service routine)

Getting the services of OS

How do the user programs get the service of OS?

User programs access the functionality of the OS through system calls privileged operations.

Example : open(), close(), fork(),…….

The execution of system call change the execution mode of the CPU to supervisor mode.

Processes

Process is a fundamental concepts in modern operating systems.

It was first introduced by the designers of Multics operating systems in the 1960s.

The programs that reside in main memory are absolutely different from their counter-parts the program files on hard disks or any other secondary storage devices.

Process and a program

A process is a program in execution

An instance of a program running on a computer.

The entity that can be assigned to and executed

on a processor

A program is a static set of instructions

Characteristics of a process

Consists of three components

An executable program

Associated data needed by the program

Execution context of the program All information the operating system needs

to manage the process.

When a new process is created, the operating system builds the date structures that are used to manage the process and allocates space in main memory to the process.

Process creation and termination

When a new process is created, the operating system builds the date structures that are used to manage the process and allocates space in main memory to the process.

A process may terminates in a number of ways.

After completion of the instructions.

User terminates (kills) the process explicitly. For example clicking on the cross button in the windows applications.

A process may terminate due to abnormal condition.

When a process finishes, the operating system will free the memory space it occupies and remove the data structures it allocated to manage the process.

Processes in a typical

Linux system

Processes in a typical Linux system Operating Systems 45

Uniprocessor Scheduling

Type of processes

I/O bound processes

Processor bound processes

Uniprocessor Scheduling

Types of Scheduling

Long-term scheduling(Job scheduling) : It determines which programs are admitted to the system for processing. Job scheduler selects processes from the queue and loads them into memory for execution. Process loads into the memory for CPU scheduling.

Medium-term scheduling : Medium term scheduling is in charge of swapping processes between the main memory and the secondary storage.

Short-term scheduling (low-level scheduling) : Determines which ready process will be assigned the CPU when it next becomes available.

Scheduling Policies

Non-preemptive Once a process is in the running state, it will

continue until it terminates or blocks itself for I/O.

Preemptive

Currently running process may be interrupted and moved to the Ready state by the OS. Allows for better service since any one process

cannot monopolize the processor for very long

Processor Scheduling

Assigning the processor to the processes.

Turnaround time : Time required for a particular process to complete, from submission time to completion.

Response time : The time taken in an interactive program from the issuance of a command to the commence of a response to that command.

Throughput : Number of processes completed per unit time. May range from 10 / second to 1 / hour depending on the specific processes.

Waiting time : How much time a process spends in the ready queue waiting its turn to get on the CPU.

Long-term scheduling(Job

scheduling)

Determines which processes are admitted to

the system for processing

Controls the degree of multiprogramming If more processes are admitted

better CPU usage

less likely that all processes will be blocked

The long term scheduler may attempt to keep a mix of processor-bound and I/O-bound processes

Medium-Term Scheduling

Swapping decisions based on the need to

manage multiprogramming

Done by memory management software

Short-Term Scheduling

Determines which process is going to execute

next (also called CPU scheduling)

The short term scheduler is known as the dispatcher Dispatching the CPU to the process

Schedulers - Comparison

Long Term Scheduler

Short Term Scheduler

Medium Term Scheduler

Job Scheduler

CPU scheduler

Processes swapping scheduler

Selects processes from a pool and loads them into the memory for execution

Selects those processes which are ready to execute for dispatching

Re-introduces the processes into memory and execution can be continued.

Controls the degree of multiprogramming

Provides lesser control over the degree of multiprogramming

Reduces the degree of multiprogramming

Speed is lesser than short term scheduler

Speed is fastest among other two

Speed is in between (short and long term schedulers)

Queuing Diagram

for Scheduling

Seven state process transition Diagram

Typically, new processes are not in the main memory.
Typically, new
processes are not in the
main memory.

Seven state process transition Diagram

Long Term Scheduler Short Term Scheduler
Long Term
Scheduler
Short Term
Scheduler

Medium Term Scheduler

Process Control Block (PCB)

All of the information needed to keep track of a process when switching states is kept in a data package called a process control block. The process control block typically contains:

An ID number that identifies the process

Pointers to the locations in the program and its data where processing last occurred

Register contents

States of various flags and switches

A list of files opened by the process

The priority of the process

The status of all I/O devices needed by the process

Context Switching

A context switch is the mechanism to store and restore the state or context of a CPU in Process Control block so that a process execution can be resumed from the same point at a later time.

Using this technique a context switcher enables multiple processes to share a single CPU. Context switching is an essential part of a multitasking operating system features.

When the scheduler switches the CPU from executing one process to execute another, the context switcher saves the content of all processor registers for the process being removed from the CPU, in its process control block.

Context switch time is pure overhead.

Context switching can significantly affect performance as modern computers have a lot of general and status registers to be saved.

Context Switching

Context Switching Operating Systems 59

Short-term scheduling algorithms

First-come-first served

Round Robin

Shortest Process next

Objectives of Short-

Term Scheduling

User-oriented

Response Time: Elapsed time from the

submission of a request to the beginning of response

Turnaround Time: Elapsed time from the

submission of a process to its completion

System-oriented

processor utilization

fairness

throughput: number of process completed per unit time

First-come-first served scheduling

Each process joins the end of the Ready queue.

When the current process ceases to execute,

the process waited the longest time in the Ready queue is assigned the CPU.

Example - FCFS

Process

Arrival

Service

Finish

Turnaround

Time

Time

time

time

A 0

 

3

3

3

B 2

 

6

9

7

C 4

 

4

13

9

D 6

 

5

18

12

E 8

 

2

20

12

Average Turnaround time

= (3 + 7+ 9+ 12 + 12)/5

= 8.60

18 12 E 8   2 20 12 Average Turnaround time = (3 + 7+ 9+

Shortest Job First

(Shortest Process Next)

Nonpreemptive policy

Process with shortest expected processing time

is selected next

Short process jumps ahead of longer processes

Shortest Job First

(Shortest Process Next)

Process

Arrival

Service

Finish

Turnaround

Time

Time

time

time

A 0

 

3

3

3

B 2

 

6

9

7

C 4

 

4

15

11

D 6

 

5

20

14

E 8

 

2

11

3

Average Turnaround time

= (3 + 7+ 11+ 14 + 3)/5

= 7.60

5 20 14 E 8   2 11 3 Average Turnaround time = (3 + 7+

FCFS - Issues

A short process may have to wait a very long time before it can execute Favors CPU-bound processes I/O processes have to wait until CPU-bound process completes

Round Robin Scheduling

Clock interrupt is generated at periodic intervals.

When an interrupt occurs, the currently

running process is placed in the ready queue (preempted)

Next process in the ready queue is assigned

the CPU.

Known as time slicing

Queuing Diagram

Round Robin Scheduling

Scheduling Policy Preemption, Time quantum for each process = 1

Process

Arrival

Service

Finish

Turnaround

Time

Time

time

time

A 0

 

3

4

4

B 2

 

6

18

16

C 4

 

4

17

13

D 6

 

5

20

14

E 8

 

2

15

7

0

5

Average Turnaround time = (4 + 16+ 13+ 14 + 7)/5 = 10.80

10

15

20

E 8   2 15 7 0 5 Average Turnaround time = (4 + 16+ 13+

Round Robin Scheduling

Scheduling Policy Preemption, Time quantum for each process = 4

Process

Arrival

Service

Finish

Turnaround

Time

Time

time

time

A 0

 

3

3

3

B 2

 

6

17

15

C 4

 

4

11

7

D 6

 

5

20

14

E 8

 

2

19

11

Gantt Chart ?

Average Turnaround time = ( 3+ 15+ 7+ 14 + 11)/5 = 10.00

Priority Scheduling

Scheduler will always choose a process of

higher priority over one of lower priority

Use multiple ready queues to represent multiple levels of priority

Lower-priority may suffer starvation

Allow a process to change its priority based on its age or execution history

Priority Queuing

Can be either preemptive or non-preemptive
Can be either preemptive or non-preemptive

Threads

A thread is the smallest schedulable unit in a system that can be managed independently by an operating system. A thread can also be viewed as an execution streams within a single process. Generally a thread contained inside a process. It is possible to have processes with one threads or processes with multiple threads.

All threads of a process share common code, data, and other resources, including CPU registers.

Allows multiple tasks to be performed simultaneously in a single address space.

Context switching generates less overhead.

Threads …

Threads are very useful whenever a process has multiple tasks to perform independently of the others.

For example in a word processor, a background thread may check spelling of a document while a foreground thread processes user keystrokes, while another thread may automatically backs up the edited section periodically.

Virtual Memory

Virtual Memory - Goals

Allow applications larger than physical memory to execute.

Run partially loaded programs.

Multiprogramming: Many programs simultaneously reside in memory.

Allow re-locatable programs anywhere, anytime

Application Portability:

Applications should not have to manage memory resources

Write machine independent code program should

not depend on memory architecture.

Permit sharing of memory segments or regions.

For example, read-only code segments should be

shared between program instances.

Virtual Memory

Address Translation

• Memory management unit (MMU) translate virtual address into physical address. • Each process has
• Memory
management unit
(MMU) translate
virtual address into
physical address.
• Each process has its
own memory space

Virtual Memory

Process runs on a virtual machine as defined

by the underlying hardware.

Focus is on Hardware support for a virtual address space virtual addresses independent of physical memory

Key hardware component is the Memory Management Unit (MMU)

address translation: virtual to physical memory

ensures virtual address space protection

Virtual Memory

Keep track of whether a page is in a physical page frame or not.
Keep track of
whether a
page is in a
physical page
frame or not.

Using Virtual Memory

Using Virtual Memory http://www.tutorialspoint.com/operating_system/os_virtual_memory.htm Operating Systems 81

http://www.tutorialspoint.com/operating_system/os_virtual_memory.htm

Using Virtual Memory

Check an internal table for this process, to determine whether the reference was a valid or it was an invalid memory access.

If the reference was invalid, terminate the process. If it was valid, but page have not yet brought in, page in the latter.

Find a free frame.

Schedule a disk operation to read the desired page into the newly allocated frame.

When the disk read is complete, modify the internal table kept with the process and the page table to indicate that the page is now in memory.

Restart the instruction that was interrupted by the illegal address trap. The process can now access the page as though it had always been in memory. Therefore, the operating system reads the desired page into memory and restarts the process as though the page had always been in memory.

Virtual Memory - Disadvantages

Space: Translation tables and other data used by VM system reduce available memory to programs

Time: Address translation time is added to the cost (execution time) of each instruction.

Overhead: Memory management operations have been measured to consume up to 10% of the CPU time on a busy system.

Efficiency: Allocating memory in pages may result in fragmentation

Virtual Memory

Allows programmers to address memory from a logical point of view

Another layer of indirection

Allow the illusion of operating with a larger memory space than what is available in reality

By storing some of the information on the file system

Device Drivers

Device driver is a software. The computer communicates with peripheral devices through device drivers.
Device driver is a software.
The computer communicates
with peripheral devices through
device drivers.

A driver provides a software interface to hardware devices, enabling operating systems and other computer programs to access hardware functions without knowing the precise hardware details.

Device drivers depends on both the hardware and the operating system loaded in to the computer

Secondary Storage Management

Secondary storage is the non-volatile repository for both user and system data and programs.

Secondary storage is typically used to store

Source program

Executable programs

Data for the program

Temporaty data

Files

A file is a named collection of related information, usually a sequence

of bytes

A file can be viewed in two different ways.

Logical (programmer’s) view: how the users see the file.

Liners collection of records.

Image File rows of intensity values

Linear sequence of bytes.

Physical (operating system) view: how the file is stored on secondary storage.

Many possibilities, not necessarily contiguous

File Attributes

Each file has an associated collection

of information(attributes)

file name

Owner

type (e.g., source, data, executable)

location(s) on the secondary storage.

organization (e.g. sequential, indexed, random)

access permissions who is permitted to read/write/delete data in the file.

time and date of creation, modification, last access

file size

File Types

File can be classified into various types based on

the content.

Executable

Text

Source

Library

Compressed

Word Processor

Spread sheet.

One of the possible implementation technique of file type is to include the type as an extension to the file name.

File Access Methods

File access methods describe how the data stored in a file can be accessed

Sequential: access in order, one record after another.

Direct (random): access in any order, skipping over uninteresting records

Indexed : access in any order, but based on key value(s)

Directories

Directories are used to organize file to

logical categories.

A directory is a file that can be searched for information about other files.

Entries in the directory file are created, deleted and modified when the files they describe are create, deleted and modified.

Unix Directory structure

Unix Directory structure Operating Systems 92

File allocation

Common file allocation techniques

Contiguous

Linked

Indexed

Typically the allocation techniques allocate storage space on the basis of fixed size addressable units.

File allocation - Contiguous

Allocate disk space as a collection of adjacent/contiguous blocks. This technique needs to keep track
Allocate disk space as a collection
of adjacent/contiguous blocks.
This technique needs to keep
track of unused disk space.
Directory
File Name
Start Block No
No of Blocks
file1
00
03
file2
12
06
file3
20
11

File allocation - Contiguous

Advantages: • Simple easy access. • Easy Access. Disadvantage • File size is not known
Advantages:
• Simple easy access.
• Easy Access.
Disadvantage
• File size is not known at the
time of creation.
• Extending file size is difficult
• External fragmentation

File allocation - Linked

Inside each block a link is maintained to point to the next block of the file

Directory

File Name

Start Block No

No of Blocks

file1

00

03

block of the file Directory File Name Start Block No No of Blocks file1 00 03

File allocation - Linked

Advantages:

No external fragmentation. Files can grow easily.

Disadvantage Many seek are required to access file data

Example :

MSDOS FAT file system

Disadvantage • Many seek are required to access file data Example : MSDOS FAT file system

File allocation - Indexed

Creates a table of pointers(index) at the time of the file creation. This table is modified as new blocks are allocated for the file or removed from the file.

The index table is also saved in a block/s.

Example : UNIX file system

or removed from the file. The index table is also saved in a block/s. Example :

Formatting a storage device

Hard disks, need to be formatted before using. Formatting a disk configures the disk with a

file system so that OS can store information on the disk.

File Allocation Table(FAT)

FAT is the file systems used by Windows NT operating system.

FAT uses a file allocation table (FAT) to keep track of files in the

storage devices

FAT and the root directory reside at a fixed location of the

volume so that the system's boot files can be correctly located.

To protect a volume, two copies of the FAT are kept.

New Technology File System

NTFS (New Technology File System) is a proprietary file system developed by Microsoft. This is improvement of FAT. This improvements includes

 

The capability to recover from some disk-related errors automatically, which FAT cannot.

 

Improved support for larger hard disks.

Better security because you can use permissions and encryption to restrict access to specific files to approved users.

NTFS is a recoverable file system which keeps track of transactions against the file system in a log.

http://windows.microsoft.com/en-us/windows-vista/comparing-ntfs-and-fat-file-systems

Memory Fragmentation

Fragmentation is the unintentional division of

memory into many small free areas that cannot be used effectively.

External Fragmentation total memory

space exists to satisfy a request, but it is not contiguous.

Internal Fragmentation allocated memory

may be slightly larger than requested memory

This size difference is in memory internal to a

cannot

partition,

other process.

hence

be

used

for

any

Memory Fragmentation ….

Compaction is a technique that can be used

to deal with (external) fragmentation by moving partitions to bring many small free areas together to form a single large free area.

References

Operating System Concepts by Avi Silberschat, Peter Baer Galvin and Greg Gagne

http://codex.cs.yale.edu/avi/os-book/OS8/os8c/slide-dir/