1 chapter 1: introduction what is the aim of the subject? what is the aim of the subject? why are...

44
1 Chapter 1: Introduction Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS? What is an OS? A bit of history A bit of history Some basic OS concepts Some basic OS concepts How does an OS work? How does an OS work? OS Structures OS Structures

Post on 22-Dec-2015

220 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

1

Chapter 1: IntroductionChapter 1: Introduction What is the aim of the subject?What is the aim of the subject? Why are OSes important?Why are OSes important? What is an OS?What is an OS? A bit of historyA bit of history Some basic OS concepts Some basic OS concepts How does an OS work?How does an OS work? OS StructuresOS Structures

Page 2: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

2

The Aim of the SubjectThe Aim of the Subject

WILL NOT TEACH YOU HOW TO USE AN WILL NOT TEACH YOU HOW TO USE AN OPERATING SYSTEM.OPERATING SYSTEM.

It will examineIt will examine the way in which an OS worksthe way in which an OS works the algorithms and data structures inside the algorithms and data structures inside

an OSan OS the problems, solutions and trade offs in the problems, solutions and trade offs in

designing an OSdesigning an OS

TO ACHIEVE AN UNDERSTANDING OF TO ACHIEVE AN UNDERSTANDING OF HOW AN OPERATING SYSTEM WORKS.HOW AN OPERATING SYSTEM WORKS.

Page 3: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

3

Computer System Computer System ComponentsComponents

• Application Software : Bank automation system, airline reservations, payroll etc.

• System Software : OS, data base, compilers, editors etc.

Page 4: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

4

What is SYSTEM What is SYSTEM SOFTWARE?SOFTWARE?

System software provides the System software provides the environment and the tools to create environment and the tools to create the application software (sort of the application software (sort of virtual machine)virtual machine)

It is also the interface between the It is also the interface between the hardware and the applicationshardware and the applications

Page 5: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

5

Why is the OS Why is the OS Important?Important?

The operating system is the The operating system is the foundation upon which all computing foundation upon which all computing work is performed.work is performed.

Knowledge of the internals of an OS Knowledge of the internals of an OS is essential to achieve efficiency inis essential to achieve efficiency in building software applicationsbuilding software applications deciding upon a computing platformdeciding upon a computing platform

Page 6: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

6

What is an Operating What is an Operating System?System?

A big, complex program (sometimes A big, complex program (sometimes many)many)

It has two main purposes in lifeIt has two main purposes in life An interface between the user and the An interface between the user and the

hardware (provides a virtual machine)hardware (provides a virtual machine) Provide efficient, safe management of Provide efficient, safe management of

computing resourcescomputing resources

Page 7: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

7

Life without an OSLife without an OS

Every programmer wouldEvery programmer would have to know the hardwarehave to know the hardware be able to access the hardwarebe able to access the hardware

Every programEvery program would contain code to do the same thingwould contain code to do the same thing probably do something wrongprobably do something wrong

Page 8: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

8

Where does the OS Fit?Where does the OS Fit?

HardwareCPU & MemoryI/O Devices

Operating System

System Calls

Users and User Programs

Page 9: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

9

History :History :First Generation (1945-First Generation (1945-

1955)1955) Vacuum tubesVacuum tubes No operating systemNo operating system Programming is done by wiring a Programming is done by wiring a

plug boardplug board Applications are mostly numerical Applications are mostly numerical

calculations (trajectory calculations (trajectory computations, computation of tables computations, computation of tables such as sine, cosine etc.)such as sine, cosine etc.)

Page 10: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

10

History:History:Second Generation Second Generation

(1955-1965)(1955-1965) TransistorsTransistors Commercially produced computersCommercially produced computers Very expensive and very slow Very expensive and very slow

computers compared with your old computers compared with your old PC at homePC at home

Batch operation (collect jobs, run in Batch operation (collect jobs, run in one go, print all outputs)one go, print all outputs)

Page 11: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

11

Spooling (Simultaneous Peripheral Spooling (Simultaneous Peripheral Operation On-line)Operation On-line)

off-line spoolingoff-line spooling on-line spoolingon-line spooling

Off-line spooling : replace slow I/O Off-line spooling : replace slow I/O devices with I/O dedicated devices with I/O dedicated computers so that the main system computers so that the main system sees these machines as its I/O sees these machines as its I/O devicesdevices

Page 12: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

12

Early Batch SystemsEarly Batch Systems

• bring cards to 1401• read cards to tape• put tape on 7094 which does computing• put tape on 1401 which prints output

Page 13: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

13

A Deck of Cards A Deck of Cards (Program)(Program)

Page 14: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

14

Applications are mostly scientific Applications are mostly scientific and engineering calculations (eg., and engineering calculations (eg., solution of partial differential solution of partial differential equations)equations)

High level languages such as High level languages such as FORTRAN and COBOLFORTRAN and COBOL

Page 15: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

15

History:History:Third Generation (1965-Third Generation (1965-

1980)1980) Integrated circuits (small scale) Integrated circuits (small scale)

packed as chipspacked as chips I/O processors (channels) which can I/O processors (channels) which can

work in parallel with CPU - work in parallel with CPU - MultiprogrammingMultiprogramming

Page 16: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

16

Multiprogramming system Multiprogramming system - - tthree jobs in memoryhree jobs in memory

Page 17: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

17

On-line spooling (using channels)On-line spooling (using channels) Time-sharing (TTY terminals and Time-sharing (TTY terminals and

VDU’s)VDU’s) Multics OS - original UNIX Multics OS - original UNIX

Minicomputers - Cheaper than Minicomputers - Cheaper than mainframes but with limited mainframes but with limited hardware (eg. DEC PDPx)hardware (eg. DEC PDPx)

Page 18: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

18

History:History:Fourth Generation Fourth Generation

(1980-1990)(1980-1990) Large scale integrationLarge scale integration Personal computersPersonal computers CP/M, MS DOS, Unix operating CP/M, MS DOS, Unix operating

systemssystems NetworksNetworks

Page 19: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

19

Now!Now!

Client/Server computationClient/Server computation Clients : PCs, workstations running Clients : PCs, workstations running

under Windows and UNIX operating under Windows and UNIX operating systemssystems

Servers : systems that run under Servers : systems that run under UNIX and Windows NTUNIX and Windows NT

Internet and intranet networking Internet and intranet networking (WWW) (WWW)

Page 20: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

20

Links for More HistoryLinks for More History

http://www.old-computers.comhttp://www.old-computers.com http://www.hitmill.com/computers/history/ihttp://www.hitmill.com/computers/history/i

ndex.htmlndex.html http://www.computerhistory.org/http://www.computerhistory.org/

Page 21: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

21

Important PointsImportant Points OS provides OS provides

a simpler, more powerful interfacea simpler, more powerful interface higher level serviceshigher level services

OS services only accessed via OS services only accessed via system callssystem calls

Users and programs can’t Users and programs can’t directly access the hardwaredirectly access the hardware

Set of System Calls (APIs) is Set of System Calls (APIs) is what programs think the what programs think the operating system is.operating system is.

Page 22: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

22

Some OS ConceptsSome OS ConceptsKernelKernel

The main OS program. Contains The main OS program. Contains code for most services. Always in code for most services. Always in primary memoryprimary memory

Device DriversDevice Drivers Programs that provide a simple, Programs that provide a simple,

consistent interface to I/O devicesconsistent interface to I/O devices Typically part of the kernelTypically part of the kernel

Page 23: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

23

Some OS ConceptsSome OS ConceptsProgramProgram

A static file of machine code on a A static file of machine code on a diskdisk

ProcessProcess A program in execution.A program in execution. The collection of OS data The collection of OS data

structures and resources owned structures and resources owned by a program while it is running.by a program while it is running.

Page 24: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

24

Producing an ExecutableProducing an Executable

Source Code Object File

Compile

Libraries and other Object files

Link

Executable

Page 25: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

25

#include <sys/types.h>#include <dirent.h>#include "ourhdr.h"

int main(int argc, char *argv[]){

DIR *dp;struct dirent *dirp;

if (argc != 2) err_quit("a single argument (the directory name) is required");if ( (dp = opendir(argv[1])) == NULL) err_sys("can't open %s", argv[1]);

while ( (dirp = readdir(dp)) != NULL) printf("%s\n", dirp->d_name);

closedir(dp); exit(0);

}

Functions supplied by systemlibraries.These functions will contain atrap instruction.

A Simple Program to print a directory

Page 26: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

26

RAM

User Program #1

User Program #2

trap 002

Kernel

1

2

3

System/Kernel Mode

User Mode

1. Program performs trap2. OS determines service number3. Service is located and executed.4. Control returns to user program.

4

Based on a diagram from “Modern Operating Systems” byAndrew Tanenbaum.

Page 27: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

27

Steps in Making a Steps in Making a System CallSystem Call

There are 11 steps in making the system call :

read (fd, buffer, nbytes)

Page 28: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

28

Some System Calls For Some System Calls For Process ManagementProcess Management

Page 29: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

29

Some System Calls For File Some System Calls For File ManagementManagement

Page 30: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

30

Some System Calls For Some System Calls For Directory ManagementDirectory Management

Page 31: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

31

Some System Calls For Some System Calls For Miscellaneous TasksMiscellaneous Tasks

Page 32: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

32

A A System CallSystem Call Example Example A stripped down shell:A stripped down shell:

while (TRUE) {while (TRUE) { /* repeat forever *//* repeat forever */ type_prompt( );type_prompt( ); /* display prompt *//* display prompt */ read_command (command, parameters)read_command (command, parameters) /* input from /* input from

terminal */terminal */ if (fork() != 0) {if (fork() != 0) { /* fork off child process *//* fork off child process */ /* Parent code *//* Parent code */ waitpid( -1, &status, 0);waitpid( -1, &status, 0); /* wait for child to exit *//* wait for child to exit */} else {} else { /* Child code *//* Child code */ execve (command, parameters, 0);execve (command, parameters, 0); /* execute command *//* execute command */ }}} }

Page 33: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

33

OS StructuresOS Structures

Monolithic systemsMonolithic systems Hierarchy of layersHierarchy of layers Virtual machinesVirtual machines Micro-kernel (client/server) modelMicro-kernel (client/server) model

Page 34: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

34

Monolithic SystemMonolithic System OS has no structure but is a OS has no structure but is a

collection of procedures with well collection of procedures with well defined calling interfacesdefined calling interfaces

Program - OS interface is via Program - OS interface is via supervisor calls (SVC)supervisor calls (SVC)

Interrupt Handler

Service routine

SVC

Program

Page 35: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

35

Simple structuring model for a Simple structuring model for a monolithic systemmonolithic system

Page 36: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

36

Monolithic SystemMonolithic System (Cont.)(Cont.)

OS code is a binded object program OS code is a binded object program and its source code may be logically and its source code may be logically divided intodivided into

OS main programOS main program System call service routinesSystem call service routines Utility procedures which help service Utility procedures which help service

routinesroutines

Page 37: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

37

Layered SystemLayered System

Structure of “THE” OS (a batch OS)Structure of “THE” OS (a batch OS)

Page 38: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

38

Layered SystemLayered System (Cont.) (Cont.)0. Process switching, multi 0. Process switching, multi

programming, CPU schedulingprogramming, CPU scheduling1. Memory and swap space (disk) 1. Memory and swap space (disk)

management (“segment controller”)management (“segment controller”)2. Message interpretation, job control 2. Message interpretation, job control

(JCL) functions(JCL) functions3. I/O management (virtual 3. I/O management (virtual

peripherals)peripherals)4. User programs4. User programs5. Operator5. Operator

Page 39: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

39

Layered SystemLayered System (Cont.) (Cont.)

Synchronisation between layers : Synchronisation between layers : Hardware and software Hardware and software (semaphores) interrupts(semaphores) interrupts

Each layer provides some sort of a Each layer provides some sort of a “virtual machine”“virtual machine”

Page 40: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

40

Virtual MachinesVirtual Machines

Physical HardwareVirtual Machine

OS1 OS2 OS3 OS4

User Programs

• VM provides “n” duplicates of physical hardware using software. So different Oses can work in the same machine at the same time

Page 41: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

41

What is wrongWhat is wrong so far so far?? OS is one large program that OS is one large program that provides all the required services.provides all the required services.

Anytime you add a new device you Anytime you add a new device you mustmust

get a device driver for the deviceget a device driver for the device recompile the kernel with the new device driverrecompile the kernel with the new device driver reboot the machine so the new kernel will be reboot the machine so the new kernel will be

usedused

Page 42: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

42

Micro-Kernel Micro-Kernel (Client/Server) Model(Client/Server) Model OS is a minimal core known as OS is a minimal core known as KernelKernel. .

Page 43: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

43

The kernel contains the minimum The kernel contains the minimum of functionof function memory managementmemory management basic CPU managementbasic CPU management inter-process communication (messages)inter-process communication (messages) I/O supportI/O support

Other functionality provided by Other functionality provided by user level processesuser level processes

Page 44: 1 Chapter 1: Introduction What is the aim of the subject? What is the aim of the subject? Why are OSes important? Why are OSes important? What is an OS?

44

Characteristics of KernelCharacteristics of Kernel

Makes use of message passingMakes use of message passing Easy to replace server processesEasy to replace server processes Easier to write and port OSEasier to write and port OS Design is perfect for distributed systemsDesign is perfect for distributed systems Less performanceLess performance