operating system(1)

11
Multi-tasking allows several programs to be active at the same time, although at an instant in time the CPU is doing only one instruction for one of the active programs. The operating system manages which instructions to send to the CPU Since computers are so fast, the operating system can switch the program that gets to execute on the CPU so quickly. 6 Categories of operating system's tasks Processor management - involves putting the tasks into order and paring them to manageable size before they go to the CPU. Memory Management - coordinates data to and from RAM and determines the necessity for virtual memory. Device management - provides intface between connected devices. Storage management - directs permanent data storage. Application interface - allows standard communication between software and computer. User interface - alllows to communicate with computer. Discussion: Processor management The heart of managing the processor comes down to two related issues 1. Ensures that each process and application receives enough of the processor's time to function properly

Upload: dennis-cosmod

Post on 26-May-2017

216 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Operating System(1)

Multi-tasking allows several programs to be active at the same time, although at an instant in time the CPU is doing only one instruction for one of the active programs.

The operating system manages which instructions to send to the CPU Since computers are so fast, the operating system can switch the program that gets to execute on

the CPU so quickly.

6 Categories of operating system's tasks Processor management - involves putting the tasks into order and paring them to manageable size

before they go to the CPU. Memory Management - coordinates data to and from RAM and determines the necessity for

virtual memory. Device management - provides intface between connected devices. Storage management - directs permanent data storage. Application interface - allows standard communication between software and computer. User interface - alllows to communicate with computer.

Discussion: Processor management

The heart of managing the processor comes down to two related issues1. Ensures that each process and application receives enough of the processor's time to

function properly2. Use as many processor cycles for real work as is possible

In a simple system, one with a single user and one processor, the process is busy only when it is executing the user's jobs.

However, when there are many users, such in a multiprogramming environment, or when there are multiple processes competing to be run by a single CPU, the processor must be allocated to each job in a fair and effecient manner.

Definition of terms: Program - an inactive unit, such as a file stored on a disk. A program is not a process. In OS, a

program or jobs is a unit of work that has been submitted by the user. Process - is an active entitty that requires a set of resources, including a processor and special

registers, to perform its function. A process, also called task, a single instance of a program in execution.

Thread - portion of a process that can run independently. For example, if your system allows to have a single thread of control and you want To see a series of pictus on a friend's website, you can instruct the browser to establish one connection between the two sites and downloads one picture at a time.

Processor - also known as the CPU, the part of the machine that performs the calculations and executes the programs.

Multiprogramming - requires that the processor be allocated to each job or to each process for a period of time and deallocated at an appropriate moment.

Sample scenario:Here you are, confident you can put together a toy despite the warning that some assembly is

required. Armed with the instructions and lots of patience, you embark on your task- to read the directions, collect the necessary tools, follow each step in turn, and turn out to finished product.

Page 2: Operating System(1)

The first step is to join Part A to Part B with a screw, and as you complete that task you check off Step 1. Inspired by your success, you move on to Step 2 and then Step 3. You've only just completed the third step when a neighbor is injured while working with a power tool and cries for help.

Quickly you check off Step 3 in the directions so you know where you left off, then you drop your tools and race to your neighbor's side. After all, someone's immediate need is more important than your eventual succes with the toy. Now you find yourself engaged in a very different task: following the instructions in a first-aid book and using bandages and antiseptic.

Once the injury has been successfully treated, you return to your previous job. As you pick up your tools, you refer to the instructions and see that you should begin with Step 4. You then continue with this project until it is finally completed.

In operating system terminology, you played the part of the CPU or processor. There were two programs, or jobs- one was the mission to assemble the toy and the second was to bandage the injury. When you were assembling the toy (Job A), each step you performed was a process. The call for help was an interrupt; and when you left the toy to treat your wounded friend, you left for a higher priority program. When you were interrupted, you performed a context switch when you marked Step 3 as the last completed instruction and put doen your tools. Attending to the neighbor's injury becameJob B. While you were executing the first-aid instructions, each of the steps you executed was again a process. And, of course, when each job was completed it was finished or terminated.

An interrupt is a signal to the processor emitted by hardware or software indicating an event that needs immediate attention.

The control program that handles the interruption sequence of events is called the interrupt handler.

Processor ManagerThe processor manager is a composite of two submanagers: one in charge of job scheduling and the

oth in charge of process scheduling. They're known as ghe Job scheduler and the Process scheduler.

Job Scheduling Versus Process SchedulingThe scheduling of two jobs, to assemble the toy and to bandage the injury, was on a first-come, first-

served and priority basis. Each job is initiated by the Job Scheduler based on certain criteria. Once a job is selected for execution, the Process Scheduler bDetermines when each steps, or set of steps, is executed- a decision that's also based on certain criteria. When you started assembling tne toy, each step in the assembly instructions would have been selected for execution by the Process Scheduler. Therfore, each job or program passes through a hierarchy of managers. Since the first one it encounts is the Job Schedul, this is also called the high-level scheduler. It is only concerned with selecting jobs from a queue of incoming jobs and placing them in the process queue, whether batch or intactive, based on each job's characteristics. The Job Scheduler's goal is to put the jobs in a sequence that will use all of the system's resources as fully as possible.

The Process Scheduler is the low-level scheduler that assigns the CPU to execute the processes of those jobs placec on thr READY queue by the Job Scheduler.

Job and Process StatusAs a job moves through the system, it is always in one of five states:From HOLD to

READY to

Page 3: Operating System(1)

RUNNING toWAITING toFINISHED

Process Control Blocks (PCB)Each process in the system is represented by a data structure called Process Control Block that

performs the me functions as a traveler's passport. The pcb contains the basic information about the job, including what it is, where it's going, how much of its processing has been completed, where it's stored, and how much it has spent in using resources.

A job's PCB is created when the Job scheduler accepts the job and is updated as the job progresesses from the beginning to the end of its execution.

Queues use PCB to track jobs the same wat custom officials use passports to track intnational visitors. The PCB contains all of the ta about the job needed by the operating system to manage the processing of the job. As the job move through the system, its progress is noted in the PCB.

Process SchedulingThe Process Scheduler relies on a process scheduling algorithm, based on a specific policy, to

allocate the CPU and move the jobs through the system.

o Process Scheduling Algorithm1. First-Come, First-Served - nonpreemptive scheduling algorithm that handles jobs according to

their arrival time: the earlier they arrive, the sooner they're served. It is a very simple algorithm to implement because it uses a FIFO queue.

2. Shortest Job Next (SJN) - nonpreemptive scheduling algorithm also knwn as Shortest Job First that handles jobs based on the length of their CPU cycle time.

3. Shortest Remaining Time (SRT) - the preemptive version of SJN algorithm. The processor is allocated to the job closest to completion.

4. Priority Scheduling - non preemptive algorithm and one of the most common scheduling algorithms in batch systems, even though it may give slower turnaround to some users.

5. Round Robin - preemptive scheduling allgorithm that used extensively in interactive systems. Its's easy to implement and isn't based on job characteristics but on a predetermined slice of time that's given to each job to ensure that CPU is equally shared among all active and isn't monopolized by any one job.The time slice is called a time quantum and its size is crucial to the performance of the system.

DeadlockDeadlock was known by the more descriptive phrase "deadly embrace" and that's exactly what

happens when the system freezes. It is a system-wide tangle of resource requests that begins when two or more jobs are put on hold,

each waiting for a vital resource to become available.

Sample scenario:A narrow staircase in a building. The staircase was built as a fire escape route, but people working in

the building often take the stairs instead of waiting for the slow elevators. Traffic on the staircase moves well unless two people, traveling in opposite directions, need to pass on the stairs- there's room for only one person on each step. In this example, the staircase is the system and the steps and landings are the resources. There's a landing between each floor and its wide enough for people to share it, but the stairs are not and n be allocated to only one person at a time. Problems occur when someone going up the stairs meet someone coming down, and each refuses to retreat to a wider place.

Page 4: Operating System(1)

Similarly, if two people on the landing try to pass each other but cannot do so because as one steps to the right, the other steps to the left, and vice versa, then the step-climbers will continue moving but neither will ever move forward. This is called livelock.

Memory Management The management of main memory is critical. Memory Manager is also known as random access memory, core memory, or primary storage.

Memory Management Scheme Single-User Contiguos Scheme - the first memory allocation scheme worked like this: each

program to be processed was loaded in its entirely into memory and alloted as much contiguous space in memory as it needed. The keywords are entirely and contiguous. If the program was too large and didn't fit the available memory space, it couldn't be executed.

Fixed Partitions - also called static partitions., one partition for each job. Once partition was assigned to a job, no other job could be allowed to enter its boundaries.

Partial usage of fixed partitions and the coinciding creation of unused spaces within the partition is called internal fragmentation.

Dynamic Partitions - with dynamic partitions, available memory is still kept in contiguous blocks but jobs are given only as much memory as they request when they are loaded for processing.

Before a job is loaded into memory, it is divided into parts called pages that will be loaded into memory locations called page frames.

Paged memory allocation is based on the concept of dividing each incoming job into pages of equal size.

The sections of a disk are called sectors and the sections of main memory are called page frames. Demand paging introduced the concept of loading only a part of the program into memory for

processing. One of the most important innovations of mand paging was that it made virtua memory feasible. The demand of paging scheme allows the user to run jobs with less main memory.

The capability of moving pages at will between main memory and secondary storage gave way to a new concept appropriately named virtual memory.

Cache memory is a small, fast memory used to hold selected data and to provide faster access than would otherwise be possible.

Caching is based on the idea that the system can use a small amount of expensive high speed memory work faster than main memory.

Device ManagementDevice management involves four basic functions:

1. Monitoring the status of each device, such as storage drives, printers and other peripheral devices2. Enforcing preset policies to determine which process will get a device and for how long3. Allocating the devices4. Deallocating

Types of Devices Dedicated devices - assigned to only one job at a time Shared devices - can be assigned to several processes Virtual devices - a combination of the first two: dedicated device thatbhave been transformed

into shared devices. Ex: Printer

User Interface

Page 5: Operating System(1)

Just as drivers provide a way for applition to make use of hardware subsystems without having to know every detail of the hardware's operation, applicatioon program interfaces (APIs) let application programmers use functions of the computer and operating system without having to directly keep track of all the details in the CPU's operation.