980 likes | 1k Views
This chapter discusses the functions and layers of an operating system, including the allocation process for resources. It also explores how an operating system manages programs, processes, and threads.
E N D
Chapter 11 Operating Systems
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
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
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
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
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
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)
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
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
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
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
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
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
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
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
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?
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
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?
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
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
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
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
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
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
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
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
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)
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
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
Use of PCB • OS uses PCB to manage processes • Resource allocation • Secure resource access • Protect active processes from interfering with each other
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
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)
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
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
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
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
Thread states • An active thread can be in one of the following states: • Ready • Running • Blocked
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
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
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
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
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
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
Scheduling methods • Common scheduling methods: • Preemptive scheduling • Priority-based scheduling • Real-time scheduling