• No results found

lecture 9 chapter 2

N/A
N/A
Protected

Academic year: 2020

Share "lecture 9 chapter 2"

Copied!
38
0
0

Loading.... (view fulltext now)

Full text

(1)

07/10/2020 1

Lecture 9

Chapter 2

Processes and Threads

discover yourself

(2)

Scheduling

The problem of determining when processors should be assigned and to which processes is called processor scheduling or CPU scheduling.

When more than one process is runable, the operating system must decide which one first. The part of the operating system concerned with this decision is called the scheduler, and algorithm it uses is called the

scheduling algorithm.

discover yourself

(3)

07/10/2020 3

Long-term Scheduling

Medium-term SchedulingShort-term Scheduling

Types of Scheduling

discover yourself

(4)

Long-Term Scheduling:

1. The decision to add to the pool of processes to be executed.

2. Selects process and loads it into memory for execution.

discover yourself

(5)

07/10/2020 5

Medium-Term Scheduling:

1. The decision to add to the number of processes that are partially or fully in main memory.

2. The mid-term scheduler temporarily removes processes from main memory and places them on secondary memory (swapping)

3. Suspend processes for which adequate resources are not currently available.

discover yourself

(6)

Short-Term Scheduling

If a process requires a resource (or input) that it does not

have, it is removed from the ready list (and enters the WAITING state)

 The decision as to which available process will be executed by the processor.

discover yourself

(7)

07/10/2020 7

Scheduling and process state transitions

discover yourself

(8)

Queuing Diagram for Scheduling

discover yourself

(9)

07/10/2020 9 discover yourself

(10)

discover yourself

(11)

07/10/2020 11

Class Work

discover yourself

(12)

Summary

Long-term: which process to admit?

Medium-term: which process to swap in or out?

Short-term: which ready process to execute next?

discover yourself

(13)

07/10/2020 13

When to Schedule?

There are variety of situations in which scheduling is needed.

1. When a new process is created, a decision needs to be made whether to run the parent process or the child process.

2. When a process exits, so some other processes must be chosen from the set of ready processes.

3. When I/O interrupt occur and now be ready to run when I/ O interrupt finishes. The decision has to be made whether to run newly ready process or the process that was running at the time of interrupt.

discover yourself

(14)

CPU Scheduling GOALS

Fairness- makes sure each process gets its fair share of the CPU.

Efficiency–keep the CPU busy 100 percent of the time.

Waiting time- minimize waiting time for job.

Turnaround – minimize the time, how long batch users must wait for output.

Throughput – maximize the number of jobs processed per hour.

discover yourself

(15)

07/10/2020 15

Summary

CPU utilization – keep the CPU as busy as possible

keep the CPU busy 100 percent of the time.

Throughput – # of processes that complete their execution per time unit.

Maximize the number of jobs processed per hour.

Turnaround time (TAT) – amount of time to execute a particular process. Time for each process to complete. Minimize the time, how long batch users must

wait for output. Time from submission to completion

Waiting time – amount of time a process has been waiting in the ready queue.

Response time – amount of time it takes from when a request was submitted until the first response is produced. Time used by the system to respond to the user job

discover yourself

(16)

Non-preemptive Scheduling

A scheduling discipline is non-preemptive if, once a process has been given the CPU, the CPU cannot be taken away from that process.

Preemptive Scheduling

A scheduling discipline is preemptive if, once a process has been given the CPU can taken away.

discover yourself

(17)

07/10/2020 17

Types of Scheduler Types of Scheduler

Primary Scheduler Secondary Scheduler

discover yourself

(18)

Primary Scheduler

1. Runs threads with the highest priority.

2. It then compares their priority and assigns resources to them, depending on their priority.

3. Threads with the highest priority will be executed for the current time slice.

4. With two or more threads with the same priority, they are put on a stack to allow each run on a given time slice.

discover yourself

(19)

07/10/2020 19

Secondary Scheduler

1. It is responsible for increasing the priority of non-executing threads.

2. It is important that those low-priority threads are given a chance to run on the operating system and this is the function of this type of scheduler.

discover yourself

(20)

1. FCFS Scheduling

2. Round Robin (RR) Scheduling 3. SJF Scheduling

4. SRTN Scheduling 5. Priority Scheduling

6. Multilevel Queue Scheduling

CPU Scheduling Algorithm

discover yourself

(21)

07/10/2020 21 discover yourself

(22)

1. First-In-First-Out (FIFO) 2. Run-to-Completion

3. Run-Until-Finish

Processes are dispatched according to their arrival time on the ready queue. Being a non-preemptive discipline, once a process has a CPU, it runs to completion.

FCFS Scheduling

discover yourself

(23)

10/07/2020 23

1. Runs the processes in the order they arrive at the short-term scheduler

2. Removes a process from the processor only if it blocks (i.e., goes into the Wait state) or terminates

3. Wonderful for long processes when they finally get on.

4. Terrible for short processes if they are behind a long process.

discover yourself

(24)

discover yourself

(25)

10/07/2020 25

discover yourself

(26)

discover yourself

(27)

10/07/2020 27

discover yourself

(28)

Suppose we change the order of arriving

job P2, P3, P1

discover yourself

(29)

10/07/2020 29

The problem with FCFS is that the average waiting time can be long. Consider the following processes

This gives us an average waiting time of 21ms (i.e. (0 + 27 + 36) /3 ).

Now consider if the processes had arrived in the order P2, P3, P1. The average waiting time would now be 6.6ms (i.e. (0 + 9 + 11) /3).

Process Burst Time

P1 27

P2 9

P3 2

discover yourself

(30)

Burst Waiting Turnaround Process Time Time Time

P1 24 0 24

P2 3 24 27

P3 3 27 30

Average - 17 27

If the processes arrive in the order P1, P2, P3 and are served in FCFS order, we get the result in the following chart

discover yourself

(31)

10/07/2020 31

discover yourself

(32)

discover yourself

inspire posterity

Process Wait Time : Service Time - Arrival Time

P0 0 - 0 = 0

P1 5 - 1 = 4

P2 8 - 2 = 6

P3 16 - 3 = 13

(33)

10/07/2020 33 Process Burst P1 24 P2 3 P3 3

CLASS WORK-1

FCFS Scheduling

Assume processes arrive in this order P1, P2, P3

Calculate the average waiting time and turnaround time?

discover yourself

(34)

Process Burst

P2 3

P3 3

P1 24

CLASS WORK-2

FCFS Scheduling

Assume processes arrive in this order P2, P3, P1

Calculate the average waiting time & turnaround time?

discover yourself

(35)

10/07/2020 35

discover yourself

inspire posterity

Process P1 P2 P3 P4 P5 Arrival Time 12 8 10 9 7

Burst Time 5 6 11 11 9

Problem

Practice Sheet — CPU Scheduling

Consider the following set of processes with the arrival time and the length of the CPU burst time given in milliseconds:

(a) FCFS (First-Come-First-Served)

(36)

Advantages and Disadvantages

Advantages:

1. simple

2. easy to understand & implement 3. first come first served

Disadvantages:

4. This scheduling method is non-preemptive, the process will run until it finishes.

5. Because of this non-preemptive scheduling, short processes which are at the back of the queue have to wait for the long process at the front to finish.

6. Poor in performance as average wait time is high.

discover yourself

(37)

10/07/2020 37

discover yourself

(38)

discover yourself

References

Related documents

On the Saudi Gulf coast the major environmental effects of coastal and marine use.. are concentrated in and around, Jubayl and

The summary resource report prepared by North Atlantic is based on a 43-101 Compliant Resource Report prepared by M. Holter, Consulting Professional Engineer,

The key segments in the mattress industry in India are; Natural latex foam, Memory foam, PU foam, Inner spring and Rubberized coir.. Natural Latex mattresses are

• how they and others choose and adapt features and functions of spoken language for specific purposes in different contexts. • some common influences on spoken language and

In summary, we have presented an infant with jaundice complicating plorie stenosis. The jaundice reflected a marked increase in indirect- reacting bilirubin in the serum. However,

1.10.3 Experiences of building relationships with PEH in the context of providing healthcare 29 1.10.4 Experiences of building relationships with young people

Using the World Bank’s Enterprise Surveys database, they find that reported constraints reflect country characteristics and vary systematically by level of income—the most

The statements, findings, conclusions, views and opinions contained and expressed here are based in part on 1996-2008 data obtained under license from IMS Health Incorporated: