Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 11 Operating Systems.

Similar presentations


Presentation on theme: "Chapter 11 Operating Systems."— Presentation transcript:

1 Chapter 11 Operating Systems

2 Chapter goals Describe the functions and layers of an operating system
List the resources allocated by the operating system and describe the complexities of the allocation process Describe how an operating system manages programs, processes, and threads

3 Chapter goals cont. Compare and contrast alternative CPU scheduling methods Explain how the operating system manages memory Describe signals and pipes and how they are used to coordinate threads and processes

4 Role of the Operating System
Critical component of all modern information systems Users and application programs depend on OS to manage Access to hardware & software resources Efficient time management of computer resources Security and data protection

5 OS Functions

6 OS Management functions
Divided between functions related to managing hardware resources (CPU and memory) management tasks oriented to users and their programs Focus of this chapter will be on CPU, memory, and process management

7 OS hardware management
All running programs require access to CPU and memory (RAM) in order to execute Early computers executed one program at a time Modern computers can simultaneously execute many programs at the same time

8 CPU and memory management
Although it appears, that programs are running simultaneously, there is only one CPU CPU can only execute one instruction at a time (although that time requirement is extremely short)

9 OS management OS keeps track of
What resources are available What programs are currently running OS decides what program gets what resource OS decides what program gets to execute

10 OS management Computer can have hundreds or even thousands of programs executing at the same time (mainframe) OS tracks programs from start to finish Processes all requests for resource allocation and communication

11 OS management cont. All executing programs compete for access to limited RAM and a small number (or a single) CPU OS controls what programs have what resources and for how long

12 OS layers Like most complex software operating systems are organized into layers (Figure 11-3) One layer can be modified without changing another layer Outer layer provides services to users and application programs Inner layer connects to hardware resources

13 OS Layers

14 OS layers cont. Command Layer – the user’s interface to the operating system Unix/DOS commands like DIR, XCOPY Windows/GUI icons can also invoke OS functions. Example: changing desktop settings Service Layer – contains a set of functions called by application programs and the command layer File access – open, save, close Kernel – manages resources and directly interacts with computer hardware Interacts with device controllers and other hardware elements of the computer

15 Kernel Portion of OS that interacts with hardware
Contains a set of interface programs called device drivers As hardware is updated or installed, device drivers are added or modified **demo device drivers by running add new hardware

16 OS Kernel

17 Resource allocation Early computers could only manage to execute one program at a time As computers grew more powerful could manage more than one executing program at a time OS needs to keep track of each executing program and keep them out of each other’s way

18 Single tasking OS Involves two executing programs
Application Operating system MS-DOS is a single-tasking operating system Most service calls are actually indirect requests for system resources

19 Multiple process resource allocation
All modern OS are able to manage multiple processes Difference between DOS and Windows Obviously this is a more complicated problem What management problems must OS solve to allow multi-tasking?

20 Multi-process OS Management problems include:
Deciding which process gets the CPU Deciding which process gets a resource Keeping track of processes while suspended Swapping out one process and replacing with another Keep processes separate

21 Multi-tasking OS and large scale application systems are composed of semi-independent modules or processes Word processor printer formatting and interface functions can be in a separate module Think about functions WP can perform What other WP functions could be separated into modules?

22 Multi-tasking cont. Modules can be loaded into memory as needed and suspended when task is complete Modules can operate independently User can continue with other WP tasks while a document is printing

23 System software multi-tasking
System software functions are also better managed as independent modules Network interface process can be loaded into memory and suspended until needed Dividing OS tasks among processes makes the entire system easier to build and upgrade

24 Resource allocation goals
A multi-tasking OS manages hardware resources according to the following goals Meet the resource needs of processes Prevent processes from interfering with each other Efficiently use hardware and other resources

25 Managing multiple processes
This requires detailed records of available resources knowing which resources are used to satisfy which requests Scheduling resources based on specific allocation policies to meet present and anticipated demands Updating records to reflect resources commitment and release by processes and users

26 System overhead The resources needed by the OS in order to manage multiple processes is called system overhead Goal is to minimize system overhead as much as possible, while still providing enough support for executing processes

27 Expanding system resources
In order to accommodate as many executing processes as possible the OS can expand a computer’s real resources by using virtual resources Real resource – a computer system’s physical devices and associated system software Virtual resource – the resources that are apparent to a process or user

28 OS resource management
Providing virtual resources that meet or exceed real resources is achieved by Rapidly shifting resources unused by one process to other processes that need them Substituting one type of resource for another when possible and necessary Main example – virtual memory Secondary storage (hard drive) extends main memory

29 What is a process? Multi-process OS is capable of managing several programs running at once Programs are usually sub-divided into separate, independent sections Process is a unit of executing software that is managed independently by the OS

30 Process definition Can request hardware resources and OS services
Stand-alone or part of group of processes that cooperate for common purpose Communicate with other processes on same computer or with processes on other computer systems (via network or internet) Look at current processes on this machine (ctrl-alt-del)

31 How OS manages processes
OS must keep track of each active process Does this with a custom data structure containing information relevant to an active process Data structure is a collection of related information

32 Process control data structures
OS keeps track of each process by creating and updating a data structure called a process control block (PCB) for each active process PCB is created when process begins Updated whenever process status changes Is deleted when process terminates

33 Use of PCB OS uses PCB to manage processes Resource allocation
Secure resource access Protect active processes from interfering with each other

34 PCB layout PCB varies from operating system to operating system
Typical data items include A unique process identification number The current state of the process Events for which the process is waiting Resources allocated exclusively to the process Machine resources consumed Process ownership and/or access privileges Scheduling priority

35 How the PCB is used PCBs for all current processes are maintained in a linked list called a process queue or process list OS frequently searches process list Looking for next process to run Looking for process that needs a specific resource Linked list is a data structure that can be easily searched Items can be easily added or deleted (unlike an array or table)

36 Process Viewer & PCBs

37 Threads Thread is a sub-unit of a process
Multiple threads can share resources allocated to parent process Thread is a sub-unit of code that can execute independently

38 Thread Control Block TCB is a data structure containing information about a thread All current TCBs are kept in a run queue or a thread list An OS capable of running multiple threads related to the same process is multi-threaded Windows 2000, Java Virtual Machine, UNIX

39 CPU Allocation Access to the CPU is the scarcest resource in the computer Most computer systems have only one or two CPUs Yet modern OS can execute hundreds or even thousands of threads within the same time frame

40 CPU sharing OS makes rapid decisions about which threads receive CPU control and for how long control is retained Typically a thread controls the CPU for a few milliseconds at a time This is called concurrent execution or interleaved execution

41 Managing Concurrent Processes

42 Thread states An active thread can be in one of the following states:
Ready Running Blocked

43 Thread states Ready – thread is ready to execute and is waiting for access to the CPU Running – thread has control of the CPU Blocked – thread is suspended while an interrupt is being processed

44 Managing Threads

45 Thread states Thread is created and dispatched (given the CPU)
Loads the instruction pointer with the starting address of that thread Thread with CPU is in the running state until Thread terminates normally An interrupt occurs

46 Threads & interrupts Interrupts can occur due to
Executing another service call, such as a request for file I/O Hardware error such as overflow or power failure Interrupt generated by peripheral device Once interrupt occurs thread loses CPU and is placed in the blocked state

47 Interrupt processing Threads are placed in the blocked state in response to an interrupt Interrupts can occur due to error conditions If error cannot be corrected the thread is halted Otherwise thread remains in blocked state until error condition is resolved

48 Interrupt example Thread attempts to access a file on a removable disk and disk is not in the drive Disk drive controller generates an interrupt CPU blocks (suspends) the thread Passes CPU control to supervisor to process the interrupt OS displays error message, and if user inserts correct disk thread is unblocked

49 Scheduling threads When more than one thread or process is competing for access to the CPU, OS must decide order of execution This is referred to as scheduling OS must apply some criteria to determine which thread goes next

50 Scheduling methods Common scheduling methods: Preemptive scheduling
Priority-based scheduling Real-time scheduling

51 Preemptive Scheduling
A thread can be removed involuntarily from the running state A running process controls the CPU by controlling the content of the instruction pointer CPU control is lost whenever an interrupt is received

52 Supervisor Portion of OS that receives CPU control after an interrupt is called the Supervisor Supervisor calls appropriate interrupt handler When interrupt handler ends Supervisor calls Scheduler

53 Scheduler Scheduler is portion of OS that manages currently executing threads Updates the status of any thread or process affected by the last interrupt Decides which thread to dispatch to CPU Updates thread control information and the stack to reflect the scheduling decision Dispatches the selected thread

54 Interrupts & Threads

55 Other interrupts Because interrupt arrival is unpredictable, time that thread remains in the run state is unpredictable Theoretically thread could control CPU indefinitely if it made no service calls Thread could get stuck in infinite loop and never relinquish CPU (demo infinite loop)

56 Timer interrupts Timer interrupts happen at regular intervals (i.e. every two hundred CPU cycles) Opportunity for Scheduler to dispatch another thread This insures every thread gets an opportunity to make progress towards completion

57 Other scheduling methods
Priority based scheduling uses some criteria to decide which thread to dispatch First come first served Explicit priority Shortest time remaining

58 Scheduling First come first served:
The scheduler always dispatches the ready thread that has been waiting the longest Explicit priority: Uses a set of priority levels and assigns a level to each process or thread The scheduling method can use priority levels in two ways: Always dispatch the highest priority ready thread Assign larger time slices to high priority threads

59 Thread priorities

60 Scheduling cont. Shortest time remaining:
Chooses the next process to be dispatched based on the expected amount of CPU time needed to complete the process Real-Time Scheduling: Guarantees minimum amount of CPU time to a thread if the thread makes an explicit request when it is created Used when a thread must have enough resources to complete its function within a specified time (i.e. ATM bank transaction)

61 Memory allocation Every executing process thread needs space in memory
Instructions Data Every process needs memory that it does not share with other processes (i.e. its data & instructions are unique to that process)

62 Memory allocation cont.
The more currently executing processes, the greater the demand on memory resources Often demand for memory can exceed the supply Solution is virtual memory – image of memory for suspended processes swapped out to disk until process is re-started

63 Single-tasking Single-tasking memory allocation must divide memory between OS and single executing application Contiguous allocation places application process adjacent to OS

64 OS Memory Management

65 Non-contiguous allocation
Often to save space only the more frequently used OS service calls are loaded into memory Less frequently used sections are loaded as needed into free areas in memory Since these free areas are separate this is called non-contiguous allocation

66 Non-contiguous memory

67 Multi-tasking memory allocation
Allocation and managing memory spaces for multiple executing processes is a much more complicated task Must keep track of available regions of memory Must release memory from processes that don’t need it anymore

68 Goals of Multi-tasking OS
Multi-tasking OS needs to allow as many active processes as possible Respond quickly to changing memory demands of processes Prevent unauthorized changes to a process’s memory region(s) Implement memory allocation and addressing as efficiently as possible

69 Partitioned memory In order to distribute memory among multiple processes, memory is divided in to partitions Each partition is same size Each partition can hold all or part of a process or thread Each active process gets a minimum of 1 partition

70 Memory Partitions

71 3 processes share memory with OS

72 Memory allocation table
OS maintains a memory partition table and updates it every time is allocated or released When a process ready to be loaded, OS searches table for free memory (partition), then allocates to process When process terminates, its memory is released

73 Memory Allocation Table

74 Memory Management Over Time

75 Wasted memory Continuous program loadings plus fixed size partitions leads to wasted memory Free (available) memory is broken into smaller and smaller pieces

76 Memory fragmentation Over time, this type of memory allocation results is small bits of free memory scattered throughout RAM Wasted memory is caused by Wasted (unused) memory inside a partition Fragments of free memory too small for a new process

77 Compaction One solution to fragmented memory is to periodically relocate all current processes Move processes together and group free space together Time consuming

78 Managing Free Space

79 Another solution Non-contiguous allocation can solve memory fragmentation problems Smaller fixed size partitions (~64 kb) Memory requirements of a process can be split between non-contiguous sections

80 Non-contiguous memory

81 Virtual memory management
It is not absolutely necessary for an entire process to reside in memory while executing The bare minimum is the next instruction to be fetched and any operands currently stored in memory Everything else could be stored elsewhere – i.e. in “virtual memory”

82 Virtual memory cont. If OS minimizes the memory requirements of individual processes, that allows a greater number of processes to be active OS virtual memory management needs to keep track of each part of an active process and load portions into memory as needed

83 Virtual memory cont. Virtual memory management divides an active process into partitions called pages Each page is a small, fixed size portion (~1-4 kb) Memory is also divided into pages of the same size

84 Pages & page frames Each memory page is called a page frame
During program execution one or more pages is allocated to page frames and the rest continues to reside on disk Pages are swapped into memory as needed during execution

85 Swapping pages When ever executing program attempts to access memory, OS intervenes and determines if that page is actually in memory or residing on disk Page hit – page is already in memory as code is able to execute Page fault – page needed is out on disk, needs to be swapped in, then code can execute

86 Page tables OS manages virtual memory by maintaining page tables for each active process Page table keeps track of what pages exist for the process and where they are located Location in memory or Location on hard drive

87 Process Page Table

88 Using secondary storage
Secondary storage is used in virtual memory management to extend the resources of memory A region on hard drive called the swap space is reserved for holding pages not in memory

89 Swapping pages If memory reference is to a page in swap space, that page is loaded into a page frame in memory If all the page frames are currently allocated, a page currently in memory known as the victim must be swapped out to storage

90 Swapping pages Choosing page to swap out of page frame is based on
Least frequently used Least recently used This requires OS overhead Updating information about access to pages Search page table and select pages to swap out

91 Memory protection Refers to the protection of memory allocated to one program from unauthorized access by another program Prevents errors in one program from causing errors in another program Adds OS overhead to every write operation

92 Memory management hardware
Early versions of multi-tasking, virtual memory management OSs were implemented in software This resulted in severe performance penalties Newer CPUs have built-in hardware to perform memory allocation and address resolution

93 Coordination between processes
Modern systems are made up of distributed components (processes) that may be running concurrently Often need to communicate, synchronize their activates, or exchange data Can share memory through mechanism known as a pipe

94 Inter-process shared data

95 Uses of shared memory Producer-consumer – one process creates data, other process uses data Send signals for synchronization of processes For example, print process can send signal to word processing process that print job is completed

96 Summary An operating system is the most complex component of system software The operating system allocates hardware resources to individual user processes on demand The operating system stores information about each process in a PCB

97 Summary cont. Application software is simpler to develop if programs are unaware of resource allocation functions An active thread is always in one of three states – ready, running, or blocked Memory is divided into fixed-size partitions and processes are allocated one or more memory partitions to store instructions and data

98 Summary cont. Modern operating systems implement a form of memory allocation and management called virtual memory management Processes and threads often need to synchronize their actions or transfer data among themselves using signals and pipes


Download ppt "Chapter 11 Operating Systems."

Similar presentations


Ads by Google