Вы находитесь на странице: 1из 43

Operating System Concepts

By Dr. Freddie Acosta 9th May 2011

Definition
An operating system is a suite of program which takes control over the operation of the computer. An OS can be viewed as a resource allocator.

The Computer System


Applications Programs Hardware Operating System Users

The Hardware
Provides the basic computing resources.
The Central Processing Unit (CPU) Memory I/O devices

Application Programs
Define the ways in which these resources are used to solve the computing problems of the users.
Compilers Database Systems Games Business programs

Users
People Machines Other computers

The Purpose of OS
To make the computer to operate in a convenient and efficient manner. To allow/process as many jobs as possible in a given period of time.

OS Services
Program Execution
The system must be able to load a program into memory and to run it. The program must be able to end its execution, either normally or abnormally (indicating error).

Services - Cont.
I/O Operations
A running program may require I/O. This I/O may involve a file or an I/O device. For specific devices, special functions may be desired.

Services cont.
File System manipulations
The file system is of particular interest. It should be obvious that programs need to read and write files. They also need to create and delete files by name.

Services cont.
Communications
between processes executing on the same computer; between processes executing on different computer systems that are tied together by a computer network.

Services cont.
Error Detection
Errors may occur in the CPU or memory hardware (memory error or a power failure), in I/O devices (connection error on a network, or lack of paper in the printer), or in the user program (arithmetic overflow). For each type of error, the OS should take appropriate action to ensure correct and consistent computing.

Services cont.
Resource Allocation
CPU times, memory and file storage, I/O devices etc must be allocated when there are multiple users or multiple jobs running at the same time.

Services cont.
Accounting
To keep track of which users use how much and what kinds of computer resources.

Services cont.
Protection
Involves ensuring that all access to system resources is controlled. Security of the system outsiders is also important through authentication.

Process Management
A process can be thought of as a program in execution. A process will need certain resources such as CPU time, memory, files and I/O devices to accomplish its tasks.

Process State
New : the process is being created Running: Instructions are being executed Waiting: the process is waiting for some event to occur (I/O completion) Ready: the process is waiting to be assigned to a processor Terminated: the process has finished execution

Process Scheduling
The purpose of multiprogramming is to have some process running at all times, to maximize CPU utilization. The objective of time sharing is to switch the CPU among processes so frequently that users can interact with each program while it is running.

Context Switch
Switching the CPU to another process requires saving the state of the old process and loading the save state for the new process. This task is known as context switch.

CPU Scheduling
Scheduling is a fundamental OS function. The idea of multiprogramming is that, a process is executed until it must wait. With multiprogramming, we try to use this idle time productively.

CPU Utilization
We want the CPU as busy as possible. For lightly loaded system, it should be about 40 percent. For heavily loaded system, it should be about 90 percent.

teria

Criteria cont.
Throughput
If the CPU is busy, then work is being done. One measure of work is the number of processes that are completed per time unit.

Criteria cont.
Turn Around Time
The interval from the time of submission to the time of completion is the TAT. TAT is the sum of the periods spent waiting to get into memory, waiting in the ready queue, executing on the CPU, and doing I/O.

Criteria cont.
Waiting Time
CPU scheduling algorithm does not affect the amount of time during which a process executes or does I/O; It affects only the amount of time that a process spends waiting in the ready queue Waiting time is the sum of the periods spent waiting in the ready queue.

Criteria cont.
Response Time
It is the amount of time it takes to start responding, but not the time that it takes to output that response.

Scheduling Algorithms
Non-Preemptive
Once CPU is allocated, it cant be taken back. The process has to voluntarily release the CPU.

Preemptive
The CPU can be taken away from a process if a process with higher priority has arrived or after a time quantum.

FCFS
The process that requests the CPU first is allocated the CPU first. When the CPU is free, it is allocated to the process at the head of the queue. The Convoy Effect

Example
Job No 1 2 CPU Burst Time 24 3 Arrival Time 0 0

SJF
When the CPU is available, it is assigned to the process that has the smallest next CPU burst. If two processes have the same length next CPU burst, FCFS scheduling is used to break the tie.

Example
Job No 1 CPU Burst Time 6 Arrival Time 0

2
3 4

8
7 3

0
0 0

Priority
The SJF is a special case of the general priority scheduling algorithm.
Where the priority (p) is the inverse of the next CPU burst (t): p = 1/t. The larger the CPU burst, the lower the priority, and vice versa.

Priorities
Internal
Time limits Memory requirements The number of open files Ratio of I/O Burst with CPU burst

External
Importance of the process Type and amount of funds being paid for computer use, The department sponsoring the work Political

Example
Process 1 2 Burst Time/ Arrival Time 10/0 1/1 Priority 3 1

3
4 5

2/2
1/3 5/4

3
4 2

SRTF (Preemptive Algorithm)


Process 1 AT 0 BT 8

2
3 4

1
2 3

4
9 5

Problem with SRTF


Indefinite blocking or starvation

Round Robin
Was designed for time sharing. It is similar to FCFS but preemption is added to switch between processes. A small unit of time, called time quantum (q) time slice, is defined. A q is generally from 10 to 100 ms.

Example (q=4)
Process 1 CPU 24 AT 0

2
3

3
3

0
0

RR
If q positive infinity (very large), the algorithm results to FCFS. If q 0 (very small), RR approach is called processor sharing and appears to the user as though each n processes has its own processor running at 1/n the speed of the real processor. Rule of thumb, 80% of the CPU burst is lower than q.

Multi Level Queue


Partitions the ready queue into several separate queues. The processes are assigned permanently to a queue based on some properties such as memory size, priority, process type. Each queue has its own scheduling algorithm.

Example 1
Highest priority

System Process Interactive Processes


Interactive Editing processes Batch processes

Student processes
Lowest priority

Example 2
High Priority
80% of CPU Time

System Process
Student processes
20% of CPU TIme

Low Priority

Multi Level Feedback Queue


Q=8
Q = 16

FCFS

Algorithm Evaluation
FCFS, SJF, RR (q=10)
Process
1 2 3 4 5

CPU BT 10 29 3 7 12

AT
0 0 0 0 0

Solve for Average TAT and Average WT.

Вам также может понравиться