45
Chapter : Operating-System Structures BSCS- III Prepared by: MAZHAR JAVED AWAN

Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

Embed Size (px)

Citation preview

Page 1: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

Chapter : Operating-System Structures

BSCS- III

Prepared by: MAZHAR JAVED AWAN

Page 2: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

2

Operating System Structures Objectives

Operating System Components◦ Process Management, Memory Management,

Secondary Storage Management, I/O System Management, File Management, Protection System, Networking, Command-Interpreter.

Operating System Services, System calls, System Programs

A Structural Approach to Operating Systems

OS Design and Implementation

Page 3: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

3

1.Process Management

Process - fundamental concept in OS◦ Process is a program in execution.◦ Process needs resources - CPU time, memory,

files/data and I/O devices.OS is responsible for the following

process management activities.◦ Process creation and deletion◦ Process suspension and resumption◦ Process synchronization and interprocess

communication◦ Process interactions - deadlock detection,

avoidance and correction

Page 4: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

4

2. Memory ManagementMain Memory is an array of addressable

words or bytes that is quickly accessible.Main Memory is volatile.OS is responsible for:

Allocate and deallocate memory to processes.

Managing multiple processes within memory - keep track of which parts of memory are used by which processes. Manage the sharing of memory between processes.

Determining which processes to load when memory becomes available.

Page 5: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

5

3.Secondary Storage and I/O Management

Since primary storage is expensive and volatile, secondary storage is required for backup.

Disk is the primary form of secondary storage. ◦ OS performs storage allocation, free-space

management and disk scheduling.I/O system in the OS consists of

◦ Buffer caching and management◦ Device driver interface that abstracts device

details◦ Drivers for specific hardware devices

Page 6: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

6

4. File System Management

File is a collection of related information defined by creator - represents programs and data.

OS is responsible for◦ File creation and deletion◦ Directory creation and deletion◦ Supporting primitives for file/directory

manipulation.◦ Mapping files to disks (secondary storage).◦ Backup files on archival media (tapes).

Page 7: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

7

Protection mechanisms control access of programs and processes to user and system resources.◦ Protect user from himself, user from other users,

system from users. Protection mechanisms must:

◦ Distinguish between authorized and unauthorized use.

◦ Specify access controls to be imposed on use.◦ Provide mechanisms for enforcement of access

control.◦ Security mechanisms provide trust in system and

privacy authentication, certification, encryption etc.

5. Protection and Security

Page 8: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

8

Networking (Distributed Systems)

Distributed System is a collection of processors that do not share memory or a clock.

Processors are connected via a communication network.

Advantages:◦ Allows users and system to exchange

information◦ provide computational speedup◦ increased reliability and availability of

information

Page 9: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

9

Command Interpreter System

Commands that are given to the operating system via command statements that execute◦ Process creation and deletion, I/O handling,

Secondary Storage Management, Main Memory Management, File System Access, Protection, Networking.

Obtains the next command and executes it.

Programs that read and interpret control statements also called -◦ Control card interpreter, command-line

interpreter, shell (in UNIX)

Page 10: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

10

Operating System Services◦Services that provide user-interfaces to OS◦ 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.

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

Page 11: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

11

Overview of OS Services

Page 12: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

12

Operating System Services (Cont.) One set of operating-system services provides functions that are

helpful to the user (Cont):

◦Communications – Processes may exchange information, on the same computer or between computers over a network Communications may be via shared memory or

through message passing (packets moved by the OS)

◦Error detection – OS needs to be constantly aware of possible errors May occur in the CPU and memory hardware, in I/O

devices, in user program 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

Page 13: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

13

Operating System Services (Cont.)Services for providing efficient system

operation 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,

mainmemory, 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

◦ 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, extends to defending external I/O devices from invalid access attempts

If a system is to be protected and secure, precautions must be instituted throughout it. A chain is only as strong as its weakest link.

Page 14: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

14

User Operating System Interface - CLI

CLI allows direct command entry

Sometimes implemented in kernel, sometimes by systems program

Sometimes multiple flavors implemented – shells

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

Bourne Shell CLI

Page 15: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

15

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)

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

◦ Solaris is CLI with optional GUI interfaces (Java Desktop, KDE)

Page 16: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

16

System Calls Programming interface to the services

provided by the OS Typically written in a high-level

language (C or 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)

Unix has about 32 system calls◦ read(), write(), open(), close(),

fork(), exec(), ioctl(),…..

System call sequence to copy the

Page 17: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

17

Example of Standard API Consider the ReadFile() function in the Win32 API—a function for reading from a file

A description of the parameters passed to ReadFile()◦ HANDLE file—the file to be read◦ LPVOID buffer—a buffer where the data will be read into and written

from◦ DWORD bytesToRead—the number of bytes to be read into the buffer◦ LPDWORD bytesRead—the number of bytes read during the last read◦ LPOVERLAPPED ovl—indicates if overlapped I/O is being used

Page 18: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

18

System Call Execution The user program makes a call to a library function. Library routine puts appropriate parameters at a

well-known place (registers, stack, or a table in memory).

The trap instruction is executed to change mode from user to kernel.

Control goes to operating system. Operating system determines which system call is to

be carried out. Kernel indexes the dispatch table, which contains

pointers to service routines for system calls. Service routine is executed and return parameter or

error code placed at well-known places (usually a CPU register).

Control given back to user program. Library function executes the instruction following trap.

Page 19: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

19

System Call …

Library Call

System Call

trap

Dispatch Table

Process

Service Code

Kernel Code

Page 20: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

20

API – System Call – OS Relationship

Page 21: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

21

Standard C Library Example

C program invoking printf() library call, which calls write() system call

Page 22: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

22

System Call Parameter PassingOften, more information is required than simply

identity of desired system call◦ Exact type and amount of information vary according to

OS and callThree 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

Page 23: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

23

Parameter Passing via Table

Page 24: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

24

Types of System CallsProcess controlFile managementDevice managementInformation maintenanceCommunications

Page 25: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

25

System ProgramsSystem 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

Most users’ view of the operation system is defined by system programs, not the actual system calls

Page 26: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

26

System Programs Provide a convenient environment for program development and

execution

◦ Some of them are simply user interfaces to system calls; others are considerably more complex

File management - Create, delete, copy, rename, print, dump, list, and generally manipulate files and directories

Status information

◦ Some ask the system for info - date, time, amount of available memory, disk space, number of users

◦ Others provide detailed performance, logging, and debugging information

◦ Typically, these programs format and print the output to the terminal or other output devices

◦ Some systems implement a registry - used to store and retrieve configuration information

Page 27: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

27

System Programs (cont’d) File modification

◦ Text editors to create and modify files◦ Special commands to search contents of files or perform

transformations of the text Programming-language support - Compilers,

assemblers, debuggers and interpreters sometimes provided

Program loading and execution- Absolute loaders, relocatable loaders, linkage editors, and overlay-loaders, debugging systems for higher-level and machine language

Communications - Provide the mechanism for creating virtual connections among processes, users, and computer systems◦ Allow users to send messages to one another’s screens,

browse web pages, send electronic-mail messages, log in remotely, transfer files from one machine to another

Page 28: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

28

Operating System Structures

Simple Structure Layered Approach Microkernels Virtual Machines

Page 29: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

29

Simple Structures

MS-DOS : written to provide the most functionality in the least space, so it was not divided into modules carefully

Page 30: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

30

Simple Structures … UNIX consists of two

separable parts, the kernel and the system programs.

Every thing below the system call interface and above the physical hardware is the kernel.

An enormous amount of functionality combined in one level, UNIX is difficult to enhance as changes in one section could adversely affect other areas.

Page 31: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

31

Layered Approach The OS is broken up into a number of layers Bottom layer is hardware and the topmost layer

( layer N) is the user interface A typical layer consists of data structures and a

set of routines to service the layer above it THE operating system by Dijkstra IBM’s OS/2

Page 32: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

32

Layered Approach … Modularity Each layer uses functions

and services of only lower layers

Simplifies debugging and system verification.

The major difficulty with layered approach is careful definition of layers, because a layer can only use the layers below it

Less efficient than other approaches

Page 33: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

33

Microkernel Structures the operating system by removing all non-

essential components from the kernel and implementing them as system and user level programs

Merits Main function is to provide a communication facility

between client programs and the various services that are also running in the user space.

Easier to extend the OS—new services are added to user space and consequently do not require modification of the kernel and/or its recompilation

Easier to maintain operating system code (enhancement, debugging, etc.)

OS is easier to port from one hardware to another More security and reliability Detriments:

Performance overhead of user space to kernel space communication

Mach, MacOS X Server, QNX, OS/2, and Windows NT

Page 34: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

34

Windows NT Client-Server Structure

MAC KERNEL

Page 35: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

35

Modules

Most modern operating systems implement kernel modules◦ Uses object-oriented approach◦ Each core component is separate◦ Each talks to the others over known

interfaces◦ Each is loadable as needed within the kernel

Overall, similar to layers but with more flexible

Page 36: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

36

Virtual MachinesA virtual machine takes the layered approach to its logical conclusion. It treats hardware and the operating system kernel as though they were all hardwareA virtual machine provides an interface identical to the underlying bare hardwareThe operating system creates the illusion of multiple processes, each executing on its own processor with its own (virtual) memory.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

Page 37: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

37

Virtual Machines (Cont.)

(a) Nonvirtual machine (b) virtual machine

Non-virtual Machine Virtual Machine

Page 38: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

38

Virtual Machines (Cont.)

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

Page 39: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

39

VMware Architecture

Page 40: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

40

VMWare on Windows

Page 41: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

41

The Java Virtual Machine

Page 42: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

42

Operating System GenerationOperating systems are designed to run on

any of a class of machines; the system must be configured for each specific computer site

SYSGEN program obtains information concerning the specific configuration of the hardware system

Booting – starting a computer by loading the kernel

Bootstrap program – code stored in ROM that is able to locate the kernel, load it into memory, and start its execution

Page 43: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

43

System BootOperating system must be made

available to hardware so hardware can start it◦Small piece of code – bootstrap loader, locates the kernel, loads it into memory, and starts it

◦Sometimes two-step process where boot block at fixed location loads bootstrap loader

◦When power initialized on system, execution starts at a fixed memory location Firmware used to hold initial boot code

Page 44: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

44

Operating System Design and ImplementationDesign and Implementation of OS not “solvable”,

but some approaches have proven successfulInternal structure of different Operating Systems

can vary widelyStart by defining goals and specifications Affected by choice of hardware, type of systemUser goals and System goals

◦User goals – operating system should be convenient to use, easy to learn, reliable, safe, and fast

◦System goals – operating system should be easy to design, implement, and maintain, as well as flexible, reliable, error-free, and efficient

Page 45: Chapter : Operating-System Structures BSCS- III. Operating System Structures Objectives Operating System Components ◦ Process Management, Memory Management,

45

Operating System Design and Implementation (Cont.)

Important principle to separatePolicy: What will be done? Mechanism: How to do it?

Mechanisms determine how to do something, policies decide what will be done◦The separation of policy from

mechanism is a very important principle, it allows maximum flexibility if policy decisions are to be changed later