25
Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Embed Size (px)

Citation preview

Page 1: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Review for Quiz-2Applied Operating System Concepts

Chap.s 1,2,6,7-

ECE3055b, Spring 2005

Page 2: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

• What is an operating system?

• Simple Batch Systems

• Multiprogramming Batched Systems

• Time-Sharing Systems

• Personal-Computer Systems

• Parallel Systems

• Distributed Systems

• Real -Time Systems

2

Page 3: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

What is an Operating System?

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

• Operating system goals:

– Execute user programs and make solving user problems easier.

– Make the computer system convenient to use.

• Use the computer hardware in an efficient manner.

• Make it easy to write programs by handling common tasks like text editing and file-selection dialog boxes.

3

Page 4: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

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

Computer System Components

4

Page 5: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

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.• Allocation of devices.

Types:

Batch, Parallel, Real Time, Interactive (special features)

5

Page 6: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Module 2: Computer-System Structures

• Computer System Operation

• I/O Structure

• Storage Structure

• Storage Hierarchy

• Hardware Protection

• General System Architecture

6

Page 7: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

• I/O devices and the CPU can execute concurrently.

• Each device controller is in charge of a particular device type.

• Each device controller has a local buffer.

• CPU moves data from/to main memory to/from local buffers

• I/O is from the device to local buffer of controller.

• Device controller informs CPU that it has finished its operation by causing an interrupt.

• Interrupt transfers control to the interrupt service routine generally, through the interrupt vector, which contains the addresses of all the service routines.

• Interrupt architecture must save the address of the interrupted instruction.

• Incoming interrupts are disabled while another interrupt is being processed to prevent a lost interrupt.

• A trap is a software-generated interrupt caused either by an error or a user request.

• An operating system is interrupt driven.

Interrupts

7

Page 8: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

8

Module 5: Threads

• Thread Management Done by User-Level Threads Library

• Examples

- POSIX Pthreads

- Mach C-threads

- Solaris threads

• Supported by the Kernel

• Examples

- Windows 95/98/NT

- Solaris

- Digital UNIX

Page 9: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

9

Solaris 2 Threads

Page 10: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Java Thread Management

10

• suspend() – suspends execution of the currently running thread.• sleep() – puts the currently running thread to sleep for a

specified amount of time.• resume() – resumes execution of a suspended thread.• stop() – stops execution of a thread.

Page 11: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

UNIX (POSIX) THREADMANAGEMENT

11

MAIN() thread

ptread_create()

pthread_join()

thread-1 terminates

pthread_exit()

I/O block

I/O block

Page 12: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Classical Problems

12

Producer-Consumer (Bounded-Buffer)Readers-WritersDining PhilosophersResource Allocation

Mutual ExclusionCritical Sections

Page 13: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

13

Module 6: CPU Scheduling• Basic Concepts

• Scheduling Criteria • Scheduling Algorithms• Multiple-Processor Scheduling• Real-Time Scheduling• Algorithm Evaluation

• Maximum CPU utilization obtained with multiprogramming

• CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait.

• CPU burst distribution

Page 14: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Histogram of CPU-burst Times

14

Page 15: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

CPU Scheduler• Selects from among the processes in memory that are

ready to execute, and allocates the CPU to one of them.• CPU scheduling decisions may take place when a

process:

1. Switches from running to waiting state.

2. Switches from running to ready state.

3. Switches from waiting to ready.

4. Terminates.• Scheduling under 1 and 4 is nonpreemptive.• All other scheduling is preemptive.

15

Page 16: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Find the order of processing and the run times for P1 (3 ticks), P2 (5 ticks), P3 (4 ticks), and P4 (1 tick) using (delta = 2 ticks, *where applicable) First-Come, First-Served (FCFS) Scheduling Shortest-Job-First (SJR) Scheduling

Preemptive*Non-preemptive

Round Robin* =========================================Find the exponential average T of the last 5 burst lengths(67, 89, 13, 56, 45) using a factor a =0.8 (67 is most recent) T = a*67 + a^2*89 + a^3*13 + a^4 * 56 + a^5 * 45 = a * ( 67 + a*( 89 + a*( 13 + a*(56 + a*(45 + ...)))))Find the next value if t=76 using one * and one + operation.

T = a * ( 76 + <old value>) 16

Page 17: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Thread Scheduling

• Local Scheduling – How the threads library decides which thread to put onto an available LWP.

• Global Scheduling – How the kernel decides which kernel thread to run next.

• JAVA– JVM Uses a Preemptive, Priority-Based Scheduling Algorithm

– FIFO Queue is Used if There Are Multiple Threads With the Same Priority.

JVM Schedules a Thread to Run When:– The Currently Running Thread Exits the Runnable State.

– A Higher Priority Thread Enters the Runnable StateJVM Does Not Specify Whether Threads are Time-Sliced or Not.

17

Page 18: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Module 8: Deadlocks

System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock Combined Approach to Deadlock Handling

18

Page 19: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Deadlock can arise if four conditions hold simultaneously.

Mutual exclusion: only one process at a time can use aresource.

Hold and wait: a process holding at least one resource iswaiting to acquire additional resources held by other

processes.

No preemption: a resource can be released only voluntarilyby the process holding it, after that process has completed its

task.

Circular wait: there exists a set {P0,P1, ...,Pn} of waitingprocesses such that P0 is waiting for a resource that is held by

P1, P1 is waiting for a resource that is held by P2, ...19

Page 20: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Resource Allocation Graph

20

Page 21: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Example of a Graph With Cycle

21

Page 22: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Ensure that the system will never enter a deadlock state.

Allow the system to enter a deadlock state and then recover.

Ignore the problem and pretend that deadlocks never occur inthe system; used by most operating systems, including UNIX.

Methods for Handling Deadlocks

22

Page 23: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Requires that the system has some additional a priori informationavailable.

Simplest and most useful model requires that each processdeclare the maximum number of resources of each type that itmay need.

The deadlock-avoidance algorithm dynamically examines theresource-allocation state to ensure that there can never be acircular-wait condition.

Resource-allocation state is defined by the number of availableand allocated resources, and the maximum demands of theprocesses.

Deadlock Avoidance

23

Page 24: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Example of Banker’s Algorithm

Which Order can P’s Run? (P1, P3, P4, P2, P0)What resources are available after P3 runs? ( 7 4 3) 24

Page 25: Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005

Allow system to enter deadlock state

Detection algorithm

Recovery scheme

Deadlock Detection

Security

Must be considered in:•Computer Hardware design•Operating System Design•Application Software Design•All of the Above 25