introduction1 operating systems university of haifa extension division

50
Introduction 1 Operating Systems University of Haifa Extension Division

Upload: paulina-bryant

Post on 28-Dec-2015

225 views

Category:

Documents


0 download

TRANSCRIPT

Introduction 1

Operating Systems

University of Haifa

Extension Division

Introduction 2

Administration

Lecturer –• Aspis Ofir

[email protected]

Course Home Page –• Yet to come…

Introduction 3

Administration

Text Books :• Applied Operating System Concepts –

Silberschatz/Galvin/Gagnehttp://www.bell-labs.com/topic/books/aos-book

• Modern Operating Systems –Tanenbaum

• Linux Programming –Stones/Matthew

• Advanced Windows –Richter

Introduction 4

What is Operating System ?

A program that acts as an intermediary between a user of a computer and the computer hardware.

Operating system goals:• A program that controls the execution of

application programs

• Make the computer system convenient to use.

• Use the computer hardware in an efficient manner.

Introduction 5

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 programs for the various users.

3. Applications 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).

Introduction 6

Abstract View of System Components

Introduction 7

Operating System Definitions

Resource allocator – manages and allocates resources.

Control program – controls the execution of user programs and operations of I/O devices .

Kernel – the one program running at all times (all else being application programs).

Introduction 8

User-Services Provided by the Operating System

Program creation• Editor and debugger utility programs

Program execution• Loading instructions, initializing I/O devices

Access to I/O devices• Making it a simple R/W command

Controlled access to files• Media technology, file format, controlling access

Introduction 9

User-Services Provided by the Operating System

Error detection and response• internal and external hardware errors

• memory error

• device failure

• software errors• arithmetic overflow

• access forbidden memory locations

Introduction 10

Operating System as a resource manager

It is actually a program that is executed by the processor to control the processor!

Directs the processor in the use of system resources

Directs the processor when executing other programs

Processor stops executing the operating system in order to execute other programs and, then, gives the control back to the operating system

Introduction 11

Operating System as a resource manager

Memory management is decided by the operating system and memory management hardware in the processor.

The operating system decides about the access of programs and files to I/O devices.

In case of multiple processors, it decides for them all

Introduction 12

A bit of history

The First Generation (1945-55) –Vacuum Tubes and Plugboards

Introduction 13

History (ctd.)

The Second Generation (1955-65)Transistors and Batch Systems• Using FORTRAN and

assembly language

• OS – FMS , IBSYS(for IBM7094)

Introduction 14

History (ctd.)

The Third Generation (1965-1980) –Multiprogramming and SpoolingThe Primary development : PDPs computer and UNIX os• Several jobs are kept in main memory at the

same time, and the CPU is multiplexed among them.

• Spooling - While executing one job, the OS:• Reads next job from card reader into a

storage area on the disk (job queue).

• Outputs printout of previous job from disk to printer.

• Job pool – data structure that allows the OS to select which job to run next in order to increase CPU utilization.

Introduction 15

OS Features Needed for Multiprogramming

I/O routine supplied by the system. Memory management – the system must

allocate the memory to several jobs. CPU scheduling – the system must choose

among several jobs ready to run.

Introduction 16

Example

JOB1 JOB2 JOB3Type of job Heavy compute Heavy I/O Heavy I/O

Duration 5 min. 15 min. 10 min.

Memory required 50K 100 K 80 K

Need disk? No No Yes

Need terminal No Yes No

Need printer? No No Yes

Introduction 17

Effects of Multiprogramming

Uniprogramming MultiprogrammingProcessor use 17% 33%

Memory use 30% 67%

Disk use 33% 67%

Printer use 33% 67%

Elapsed time 30 min. 15 min.

Throughput rate 6 jobs/hr 12 jobs/hr

Mean response time 18 min. 10 min.

• The secret is the supporting hardware for I/O interrupts and DMA

Introduction 18

Time sharing advantages

Using multiprogramming (multi-tasking) to handle multiple interactive jobs

Processor’s time is shared among multiple users

Multiple users simultaneously access the system through terminals

The objective is to minimize response time to the user commands

Introduction 19

History (cont.)

The Fourth Generation(1980 – Present) –Personal Computers

• 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

Introduction 20

Windows - History

•DOS 1.00: 4000 lines of assembly language

Introduction 21

Windows - History

DOS 2.0 in 1983, supported a hard disk, one directory, max 64 files

DOS 3.0 ran on Intel’s 286 processor, memory protection features and hard disk

DOS 3.1, 1984, supported networking DOS 3.3, 1987, supported 386 processor Windows 3.0, 1990, PC Graphical User

Interface (GUI) for the 1st time

Introduction 22

Windows - History

Windows NT developed from scratch to provide a multitasking single user environment. Version 3.1, 1993.

Windows 95-98 :Multitasking single user – not full 32bit

Win NT 4.0, 1996 – win95 GUI16 million lines of C code

Introduction 23

Characteristics of Modern Operating Systems

1. Microkernel architecture• Assigns only a few essential functions to the

kernel• address space

• interprocess communication (IPC)

• basic scheduling

• Other functions run in user mode and treated like any other application

Introduction 24

Characteristics of Modern Operating Systems

2. Multithreading• process is divided into threads that can run

simultaneously

• Thread• dispatchable unit of work

• executes sequentially and is interruptable

• Process is a collection of one or more threads

• Useful when there is no need to serialize, e.g., database that deals with several clients

Introduction 25

Characteristics of Modern Operating Systems

3. Symmetric multiprocessing• there are multiple processors transparent to the user

• these processors share same main memory and I/O facilities

• All processors can perform the same functions

• Better performance (speed), availability (fault tolerance), growth, scaling (wide price range)

Introduction 26

Multiprogramming vs. multiprocessing

Introduction 27

Operating Systems Concepts

1. Process

2. Memory management

3. Information protection & security

4. Scheduling and resource management

5. The Shell

Introduction 28

Process

A process consists of 3 components:• an executable program• associated data• execution context (PC, registers & status)

Improper synchronization• Status ensures that a process waiting for an I/O device receives

the signal Failed mutual exclusion

• Priorities are included in context Nondeterminate program operation

• program should only depend on its input, not relying on common memory or order of running with others

Deadlocks• 2 or more programs awaiting each others! More later

Introduction 29

Memory Management principals

Process isolation Automatic allocation and management Supporting long-term means of storage achieves all of the above thru virtual memory

and file system

Introduction 30

Categories of Security and Protection

Access control• regulate user access to the system and data, e.g.,

permissions

Information flow control• regulate flow of data within the system and its

delivery to users

Certification• proving that access and flow control perform

according to specifications, e.g., passwords

Introduction 31

Scheduling and Resource Management

Fairness• give equal and fair access to all processes that are

charged the same rate

Differential responsiveness• discriminate between different classes of jobs

Efficiency• maximize throughput, minimize response time,

and accommodate as many users as possible

Operations-research management problems

Introduction 32

Major elements of OS

Short-term: In memory, readyto run on the CPU

Scheduler picks one

OS moves jobs from long-termto short-term queues withoutovercommitting memory orprocessor

I/O Queue for each I/O deviceOS also decides assigning Processes to IO devices

An interrupt or a service callinvokes scheduler to pick aProcess for execution

Operating System

Service Callfrom Process

Long-TermQueue

Short-TermQueue

I/OQueues

Pass Controlto Process

Interruptfrom Process

Interruptfrom I/O

Short-TermScheduler

ServiceCall Handler

InterruptHandler

Introduction 33

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. from C,C++ , or Perl programs)

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.

Introduction 34

Passing of Parameters As A Table

Introduction 35

Passing of Parameters by the Stack

Dispatch Sys call handler

Increment SP

Call Read

Push fd

Push &buffer

Push nbytes

Return to caller

Trap to the kernelPut code for read in register

User program

Calling read

Library

Procedure

read

User space

Kernel space (OS)

1

2

3

1

45

6

7 8

9

1011

Introduction 36

Process management

Some Major POSIX system calls

Call Descriptionpid = fork() Create a child process identical to

the parent

pid = waitpid(pid,&statloc,options) Wait for a child to terminate

s = execve(name,argv,environp) Replace a process

exit(status) Terminate process execution and return status

Introduction 37

Some Major POSIX system calls

File management

Call Descriptionfd = open(file,how,…) Open a file for read/write

s = close(fd) Close an open file

n = read(fd,buffer,nbytes) Read data from a file into a buffer

n = write(fd,buffer,nbytes) Write data from a buffer into a file

Introduction 38

System Calls for Process ManagementExample: UNIX/LINUX(POSIX)

while(1) {

type_prompt();

read_command(command,parameters);

if(fork()!=0){

/*Parent code. */

waitepid(-1,&status,0);

}else{

/*Child code */

execve(command,parameters,0);

}

}

Introduction 39

Same Example in Win32

#include <stdio.h>#include <process.h>#include <windows.h>void main(){ char s[80]; STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); while(1){

printf("Shell: ");gets(s);if(!CreateProcess(NULL,s,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)) fprintf(stderr, "CreateProcess failed." );

}/* // Wait until child process exits.

WaitForSingleObject( pi.hProcess, INFINITE ); // Close process and thread handles.

CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); */

}

Introduction 40

Process Segments

Text

Data

Gap

Stack

0000

FFFF

Introduction 41

MS-DOS Execution

Introduction 42

UNIX Running Multiple Programs

Introduction 43

System Structure – Simple Approach

MS-DOS – written to provide the most functionality in the least space

Introduction 44

System Structure – UNIX

UNIX – 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.

Introduction 45

Windows NT

Kernel mode only has access to System data and hardware

Modular flexible structure.

Introduction 46

Virtual Machines

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..

Introduction 47

The Java Virtual Machine

Introduction 48

The operating System Zoo

Mainframe Operating Systems – • High-End Servers

• Processes routine jobs without any interactive user present

• OS/390 for example

Server Operating Systems• Run on Large PC or even on Mainframes

• Print , file or web services

• Unix , Windows 2000 , Linux

Introduction 49

The operating System Zoo

Multiprocessor Operating Systems• Windows 2000 (up to 32 CPUs) , SunOS

PC Operating Systems• Running users applications

• Multimedia support

• Windows 98/Me/Xp

Real-Time Operating Systems• Time as a key parameter (hard dead line)

• VxWorks , QNX

Introduction 50

The operating System Zoo

Embedded Operating Systems• Run on a computer not generally thought of as

computer, like TV ,microwave etc.

• Have some characteristics of real-time systems

• PalmOS , Windows CE

Smart Card Operating Systems• Very small - run on a credit card sized device

• Some are Java Oriented (based on JVM)