unit ii process management, thread scheduling chapter 3: process concept process conceptsconcepts...

74
UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process Concepts Chapter 4: Multithread Programming Threads Chapter 5: Process Scheduling Scheduling Criteria Algorithms – their evaluation Thread Scheduling Case Studies UNIX / Linux / Windows University Exam Questions Objective Type Questions 1 Process Management, Thread Scheduling

Upload: morgan-hampton

Post on 14-Jan-2016

237 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

UNIT IIProcess Management, Thread Scheduling

Chapter 3: Process ConceptProcess Concepts

Chapter 4: Multithread ProgrammingThreads

Chapter 5: Process SchedulingScheduling Criteria Algorithms – their evaluationThread Scheduling

Case Studies UNIX / Linux / Windows

University Exam QuestionsObjective Type Questions

1Process Management, Thread Scheduling

Page 2: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Process Concepts

• Process

• Process States

• Process Control Block (PCB)

• Switch from Process to Process

• Process Scheduling Queues

• Schedulers

• Cooperating Processes

• Inter Process Communication (IPC)

2Process Management, Thread Scheduling|<<

Page 3: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Process

• A program in execution.

• Process execution must progress in Sequential fashion.

• includes:– Program Counter – Stack– Data Section

3Process Management, Thread Scheduling|<<

Page 4: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Process States

As a process executes, it changes state

– new: The process is being created

– running: Instructions are being executed

– waiting: The process is waiting for some event to occur

– ready: The process is waiting to be assigned to a processor

– terminated: The process has finished execution4Process Management, Thread Scheduling

|<<

Page 5: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Process Control Block (PCB)

Information associated with each process

• Process State

• Program Counter

• CPU Registers

• CPU Scheduling information

• Memory Management information

• Accounting information

• I/O Status information

5Process Management, Thread Scheduling|<<

Page 6: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

CPU Switch From Process to Process

6Process Management, Thread Scheduling|<<

Page 7: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Process Scheduling Queues

• Job queue– Set of all processes in the system

• Ready queue– Set of all processes residing in main memory, ready and waiting to execute

• Device queues – Set of processes waiting for an I/O device

• Processes migrate among the various queues

7Process Management, Thread Scheduling

Page 8: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Ready Queue and Various I/O Device Queues

8Process Management, Thread Scheduling

Page 9: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Representation of Process Scheduling

9Process Management, Thread Scheduling|<<

Page 10: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Schedulers

• Long-term scheduler (or job scheduler)– Selects which processes should be brought into the ready queue

• Short-term scheduler (or CPU scheduler)– Selects which process should be executed next and allocates CPU

10Process Management, Thread Scheduling

Page 11: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Addition of Medium Term Scheduling

11Process Management, Thread Scheduling|<<

Page 12: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Cooperating Processes

• Independent process – cannot affect or be affected by the execution of another process

• Cooperating process – can affect or be affected by the execution of another process

• Advantages of process cooperation– Information sharing – Computation Speed-up– Modularity– Convenience

12Process Management, Thread Scheduling|<<

Page 13: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Interprocess Communication (IPC)

• Mechanism for processes to communicate and to synchronize their actions

• Message system – Processes communicate with each other without resorting to shared

variables

• Provides two operations:– send(message) – message size fixed or variable– receive(message)

• If P and Q wish to communicate, they need to:– establish a communication link between them– exchange messages via send/receive

• Implementation of communication link– Physical (e.g., shared memory, hardware bus)– Logical (e.g., logical properties)

13Process Management, Thread Scheduling|<<

Page 14: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Threads

• Threads

• Benefits

• User Threads

• Kernel Threads

• Multithreading Models

• Threading Issues

• Application Threads

14Process Management, Thread Scheduling|<<

Page 15: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

OS-5 Threads 15

Threads

Light Weight Process (LWP).

Basic unit of CPU utilisation.

Comprises of•Thread ID•Program Counter•Register Set•Stack

Types•User Threads•Kernel Threads

Page 16: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Single and Multithreaded Processes

16Process Management, Thread Scheduling|<<

Page 17: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Benefits

• Responsiveness

• Resource Sharing

• Economy

• Utilization of Multi Processor Architectures

17Process Management, Thread Scheduling|<<

Page 18: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

User Threads

• Thread management done by user-level threads library

• Three primary thread libraries:– POSIX Pthreads– Win32 threads– Java threads

18Process Management, Thread Scheduling|<<

Page 19: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Kernel Threads

• Supported by the Kernel

• Examples– Windows XP/2000– Solaris– Linux– Tru64 UNIX– Mac OS X

19Process Management, Thread Scheduling|<<

Page 20: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Multithreading Models

• Many-to-One Model

• One-to-One Model

• Many-to-Many Model

20Process Management, Thread Scheduling|<<

Page 21: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Many-to-One Model

• Many user-level threads mapped to single kernel thread

• Examples:– Solaris Green Threads– GNU Portable Threads

21Process Management, Thread Scheduling|<<

Page 22: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

One-to-One Model

• Each user-level thread maps to kernel thread

• Examples– Windows NT/XP/2000– Linux– Solaris 9 and later

22Process Management, Thread Scheduling|<<

Page 23: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Many-to-Many Model

• Allows many user level threads to be mapped to many kernel threads

• Allows the operating system to create a sufficient number of kernel threads

• Solaris prior to version 9• Windows NT/2000 with the ThreadFiber package

23Process Management, Thread Scheduling

Page 24: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Two-Level Model

• Similar to Many-to-Many, except that it allows a user thread to be bound to kernel thread.

• Examples– IRIX– HP-UX– Tru64 UNIX– Solaris 8 and earlier

Prof. D. S. R. Murthy 24Process Management, Thread Scheduling|<<

Page 25: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Threading Issues

• Semantics of fork() and exec() system calls

• Thread Cancellation

• Signal Handling

• Thread Pools

• Thread Specific Data

• Scheduler Activations

25Process Management, Thread Scheduling|<<

Page 26: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Thread Cancellation

• Terminating a thread before it has finished.

• General approaches:– Asynchronous cancellation

• Terminates the target thread immediately

– Deferred cancellation • Allows the target thread to periodically check,

if it should be cancelled

26Process Management, Thread Scheduling|<<

Page 27: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Signal Handling

• Signals are used in UNIX systems to notify a process that a particular event has occurred

• A signal handler is used to process signals1. Signal is generated by particular event2. Signal is delivered to a process3. Signal is handled

• Options:– Deliver the signal to the thread to which the signal applies– Deliver the signal to every thread in the process– Deliver the signal to certain threads in the process– Assign a specific thread to receive all signals for the process

27Process Management, Thread Scheduling|<<

Page 28: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Thread Pools

• Create a no. of threads in a pool where they await work

• Advantages:– Usually slightly faster to service a request with an existing thread than

create a new thread– Allows the no. of threads in the application(s) to be bound to the size of

the pool

28Process Management, Thread Scheduling|<<

Page 29: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Thread Specific Data

• Allows each thread to have its own copy of data

• Useful when you do not have control over the thread creation process (i.e., when using a thread pool)

29Process Management, Thread Scheduling|<<

Page 30: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Scheduler Activations

• Both Many-to-Many and Two-level models require communication to maintain the appropriate number of kernel threads allocated to the application

• Scheduler activations provide upcalls – A communication mechanism from the kernel to the thread library

• This communication allows an application to maintain the correct number kernel threads

30Process Management, Thread Scheduling|<<

Page 31: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Application Threads

• Pthreads

• Windows XP Threads

• Linux Threads

• Java Threads

31Process Management, Thread Scheduling|<<

Page 32: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Pthreads

• A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization

• API specifies behavior of the thread library, implementation is up to development of the library

• Common in UNIX operating systems – Solaris– Linux– Mac OS X

32Process Management, Thread Scheduling|<<

Page 33: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Windows XP Threads

• Implements the one-to-one mapping

• Each thread contains– A thread id– Register set– Separate user and kernel stacks– Private data storage area

• The register set, stacks, and private storage area are known as the context of the threads

• The primary data structures of a thread include:– ETHREAD (executive thread block)– KTHREAD (kernel thread block)– TEB (thread environment block)

33Process Management, Thread Scheduling|<<

Page 34: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Linux Threads

• Linux refers to them as tasks rather than threads

• Thread creation is done through clone() system call

• clone() – allows a child task to share the address space of the parent task

34Process Management, Thread Scheduling|<<

Page 35: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Java Threads

• Java threads are managed by the JVM

• Java threads may be created by:– Extending Thread class– Implementing the Runnable interface

35Process Management, Thread Scheduling

Java Thread States

|<<

Page 36: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

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 (Non-Preemptive)2. Switches from running to ready state (Preemptive)3. Switches from waiting to ready (Preemptive)4. Terminates (Non-Preemptive)

36Process Management, Thread Scheduling

Page 37: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Scheduling Criteria

• CPU utilization – Keep the CPU as busy as possible

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

• Turnaround time – Amount of time to execute a particular process

• 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, not output (for time-sharing environment)

37Process Management, Thread Scheduling

Page 38: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Optimization Criteria

• Max CPU utilization

• Max throughput

• Min turnaround time

• Min waiting time

• Min response time

38Process Management, Thread Scheduling|<<

Page 39: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Scheduling Algorithms

• FCFS Scheduling

• SJF Scheduling

– Non-Preemptive

– Preemptive

• Priority Scheduling

• Round Robin

• Multilevel Queue Scheduling

• Multilevel Feedback Scheduling

39Process Management, Thread Scheduling|<<

Page 40: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

FCFS Scheduling

Process Burst TimeP1 24

P2 3 P3 3

Suppose that the processes arrive in the order: P1 , P2 , P3

Gantt Chart:

Waiting time for P1 = 0; P2 = 24; P3 = 27

Average waiting time: (0 + 24 + 27) / 3 = 17

P1 P2 P3

24 27 300

40Process Management, Thread Scheduling

Page 41: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

FCFS Scheduling (Cont.)

P1P3P2

63 300

41Process Management, Thread Scheduling

Process Burst TimeP1 24

P2 3 P3 3

Suppose that the processes arrive in the order: P2 , P3 , P1

Gantt Chart:

Waiting time for P1 = 6; P2 = 0; P3 = 3

Average waiting time: (6 + 0 + 3) / 3 = 3

|<<

Page 42: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Shortest-Job-First (SJF) Scheduling

• Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time

• Schemes: – Non-Preemptive

• Once CPU given to the process it cannot be preempted until completes its CPU burst

– Preemptive / Shortest-Remaining-Time-First (SRTF) • If a new process arrives with CPU burst length less than remaining

time of current executing process, preempt.

• Optimal – Gives minimum average waiting time for a given set of processes

42Process Management, Thread Scheduling|<<

Page 43: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Process Arrival Time Burst Time

P1 0.0 7

P2 2.0 4

P3 4.0 1

P4 5.0 4

Gantt Chart:

Average waiting time = (0 + 6 + 3 + 7) / 4 = 4

Example of Non-Preemptive SJF

P1 P3 P2

73 160

P4

8 12

43Process Management, Thread Scheduling|<<

Page 44: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Example of Preemptive SJF

Process Arrival Time Burst Time

P1 0.0 7

P2 2.0 4

P3 4.0 1

P4 5.0 4

Gantt Chart:

Average waiting time = (9 + 1 + 0 +2) / 4 = 3

P1 P3P2

42 110

P4

5 7

P2 P1

16

44Process Management, Thread Scheduling|<<

Page 45: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Priority Scheduling

• A priority No. (Integer) is associated with each process

• The CPU is allocated to the process with the highest priority– Smallest integer highest priority– Preemptive– Non-preemptive

• SJF is a priority scheduling where priority is the predicted next CPU burst time

• Problem Starvation – Low priority processes may never execute

• Solution Aging – As time progresses increase the priority of the process

45Process Management, Thread Scheduling|<<

Page 46: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Round Robin (RR)

• Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds.

• After this time has elapsed, the process is preempted and added to the end of the ready queue.

• If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once.

• No process waits more than (n-1)q time units.

46Process Management, Thread Scheduling

Page 47: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Example of RR with Time Quantum = 20

Process Burst TimeP1 53 P2 17 P3 68 P4 24

Gantt chart:

Higher average turnaround than SJF, but better response

P1 P2 P3 P4 P1 P3 P4 P1 P3 P3

0 20 37 57 77 97 117 121 134 154 162

47Process Management, Thread Scheduling|<<

Page 48: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Multilevel Queue• Ready queue is partitioned into separate queues:

– Foreground (Interactive) – Background (Batch)

• Each queue has its own scheduling algorithm– Foreground – RR– Background – FCFS

• Scheduling must be done between the queues– Fixed priority scheduling;

• (i.e., serve all from foreground then from background). • Possibility of starvation.

– Time slice • Each queue gets a certain amount of CPU time which it can

schedule amongst its processes; • i.e., 80% to foreground in RR• 20% to background in FCFS

48Process Management, Thread Scheduling

Page 49: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Multilevel Queue Scheduling

49Process Management, Thread Scheduling|<<

Page 50: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Multilevel Feedback Queue• A process can move between the various queues;

– aging can be implemented this way

• Multilevel-feedback-queue scheduler defined by the following parameters:– No. of queues– Scheduling algorithms for each queue– Method used to determine when to upgrade a process– Method used to determine when to demote a process– Method used to determine which queue a process will enter when that

process needs service

50Process Management, Thread Scheduling

Page 51: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Example of Multilevel Feedback Queue• Queues:

– Q0 – RR with time quantum 8 milliseconds

– Q1 – RR time quantum 16 milliseconds

– Q2 – FCFS

• Scheduling– A new job enters queue Q0 which is served FCFS. When it gains CPU,

job receives 8 milliseconds. – If it does not finish in 8 milliseconds, job is moved to queue Q1.

– At Q1 job is again served FCFS and receives 16 additional milliseconds.

– If it still does not complete, it is preempted and moved to queue Q2.51Process Management, Thread Scheduling

|<<

Page 52: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Windows XP Priorities

52Process Management, Thread Scheduling

Page 53: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Linux Scheduling

• Time-sharing Algorithm– Prioritized credit-based

• Process with most credits is scheduled next– Credit subtracted when timer interrupt occurs– When credit = 0, another process chosen– When all processes have credit = 0, recrediting occurs

• Based on factors including priority and history

• Real-time Algorithm– Soft real-time– Posix.1b compliant

• Classes– FCFS – RR

• Highest priority process always runs first

53Process Management, Thread Scheduling|<<

Page 54: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

University Exam Questions

1.Define process. Explain various process states. [8]

2.Define process. What is the difference between a process and a program? [6]

3.What are the operations that can be performed on a process? [16]

4.Draw a neat diagram showing process states. Explain it in detail. [8]

5.Explain various steps involved in change of a process state. [16]

6.Draw the diagram that shows transition of each process among the states. Explain it. [16]

7.How the process identification & process state information in represented. [8]

8.Compare process with a program? What is the data structure used to represent a process? [8]

54Process Management, Thread Scheduling

Page 55: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

University Exam Questions

9.Explain in detail about the various reasons for process suspension. [16]

10.Explain in detail about inter-process communication. [16]

11.What is a thread? What are its benefits? [5+5]

12.Explain the concept of threads in detail. [8]

13.Explain about user level and kernel level threads. [6]

14.Compare & contrast process & thread. [8]

15.Compare & contrast multiprogramming, multi threading & multi tasking. [8]

16.What is the purpose of processor scheduling? Explain various types of scheduling for uniprocessor system. [16]

17.What is a scheduler? What are various schedules? [8]55Process Management, Thread Scheduling

Page 56: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

University Exam Questions

Assume the following are the jobs to execute with one processor:

The jobs are assumed to have arrived in the order 1, 2, 3, 4, 5.

(a)Give Gantt chart illustrating the execution of these jobs using First-Come-First-Serve, Round-Robin (quantum = 1), Shortest process next, Shortest remaining time.

(b) What is the turn around time, waiting time of each jobs for each of the above scheduling algorithms. [8+8]

56Process Management, Thread Scheduling|<<

Page 57: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Objective Type Questions

1. PCB stands for [ ] a) Process condition block b) Program counter block c) Process control block d) Program condition block

2.When a process requests for I/O, how many process switches take place? a) one b) two c)zero d) three [ ]

3. The sum of the periods spent waiting to get into memory, waiting in the ready queue, executing on the CPU, and doing I/O is called _______ time.

a) Execution b) Turnaround []

c) waiting d) response

4. Which of the following register contains address of the next instruction to be executed by the CPU? [ ]

a) IR b) PSW c) CR d) PC

57Process Management, Thread Scheduling

Page 58: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Objective Type Questions

5. The strategy of allowing processes that are logically runnable to be temporarily suspended is called __________ Scheduling. [ ]

a) preemptive b) non preemptive c) SJF d) RR

6. A process which has just terminated but has yet to relinquish its resources is called []

a) A suspended process b) A zombie process c) A blocked process d) A terminated process

7.Which of the following scheduling is more appropriate for a time-shared system. [ ]

a) FCFS b) SJF c) RR d) PRIORITY

58Process Management, Thread Scheduling|<<

Page 59: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Fill in the Blanks

1.A process, Which is ready to run but lacking the CPU can be considered, blocked and waiting for then CPU is called _____________ .

2.CPU scheduling is the basis of ______________ operating system.

3.The major problem with priority scheduling algorithm is __________.

4.The _______ is a module that gives control of the CPU to the process selected by the short term scheduler.

5.An optimal scheduling algorithm that gives the minimum average waiting time for a given set of processes is __________.

6.The average number of jobs or processes completed by the system in one unit of time is called ___________ .

59Process Management, Thread Scheduling

Page 60: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Fill in the Blanks

7.The act of selecting the next process to be serviced by a CPU is called ________.

8.A computer's throughput depends upon the extent of utilization of its ___________.

9.Early computer systems allowed only one program to be executed at a time.

10.Current day computer systems allow multiple programs to be loaded into memory and executed concurrently.

11.A process is a program in execution.

12.A process is the unit of work in a modern time-sharing system.

13.A program is a passive entity.

14.A process is an active entity.60Process Management, Thread Scheduling

Page 61: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Fill in the Blanks

15.A program counter specifies the next instruction to execute and a set of resources.

16.A program becomes a process when an executable file is loaded into main memory.

17.As a process executes, it changes state.

18.Each process is represented in the operating system by a process control block.

19.A process is a program that performs a single thread of execution.

20.The objective of multiprogramming is to have some process running at all times, to maximise CPU utilisation.

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

61Process Management, Thread Scheduling

Page 62: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Fill in the Blanks

22.The process scheduler selects an available process for program execution on the CPU.

23.For a single processor system, there will never be more than one running process.

24.A job queue consists of all processes in the system.

25.The long-term / job scheduler selects the processes and loads them into memory for execution.

26.The short-term / CPU scheduler selects from among the processes that are ready to execute and allocates the CPU to one of them.

27.The long-term scheduler controls the degree of multiprogramming.

28.No. of processes in memory is called degree of multiprogramming.

62Process Management, Thread Scheduling

Page 63: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Fill in the Blanks

29.An I/O bound process spends more time doing I/O than it spends doing computations.

30.A CPU bound process generates I/O requests infrequently, using more of its time doing computations.

31.The process is swapped out, and is later swapped in, by the medium-term scheduler.

32.The creating process is called a parent process.

33.A parent process creates a new process called a child process.

34.Most operating systems identify processes according to a unique process identifier.

35.An independent process cannot affect or be affected by the other processes executing in the system.

63Process Management, Thread Scheduling

Page 64: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Fill in the Blanks

36.An cooperating process can affect or be affected by the other processes executing in the system.

37.A cooperating process shares data with other processes.

38.Cooperating processes require an inter-process communication mechanism to communicate with each other.

39.Interprocess communication allows the processes to exchange data and information.

40.Fundamental models of inter-process communication are shared memory and message passing.

41.The producer-consumer problem is a common paradigm for cooperating processes.

64Process Management, Thread Scheduling

Page 65: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Fill in the Blanks

42. In producer-consumer problem, a producer produces information that is consumed by a consumer process.

43.Various processing states are new, ready, running, waiting, or terminated.

44.A thread is a basic unit of CPU utilisation.

45.A thread is a Light-weight process.

46.A thread comprises a thread-ID, a program-counter, a register set, and a stack.

47.A thread is a flow of control within a process.

48.User-level threads are visible to the programmer.

65Process Management, Thread Scheduling

Page 66: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Fill in the Blanks

49.The benefits of multithreading are increased responsiveness to the user, resource sharing within the process, economy, and the ability to take advantage of multiprocessor architectures.

50.The many-to-one model maps many user-level threads to one kernel thread.

51.The one-to-one model maps each user thread to a kernel thread.

52.The many-to-many model multiplexes many user-level threads to a smaller or equal no. of kernel threads.

53.Thread cancellation is the task of terminating a thread before it has completed.

54.A thread that is to be cancelled is often referred to as the target thread.

55.A signal is used in Unix systems to notify a process that a particular event has occurred.

66Process Management, Thread Scheduling

Page 67: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Fill in the Blanks

56.CPU scheduling is the basis of multiprogrammed operating systems.

57.The dispatcher gives control of the CPU to the process selected by the short-term scheduler.

58.The time taken by the dispatcher to stop one process and start another running is known as the dispatch latency.

59.No. of processes completed per time unit is called throughput.

60.The interval from the time of submission of a process to the time of completion is the turnaround time.

61.Waiting time is the sum of the periods spent waiting in the ready queue.

62.Response time is the amount of time it takes to start responding.

67Process Management, Thread Scheduling

Page 68: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Fill in the Blanks

63.CPU scheduling deals with the problem of deciding which of the processes in the ready queue is to be allocated the CPU.

64.The FCFS scheduling algorithm is nonpreemptive.

65.Preemptive Shortest Job First scheduling is called shortest-remaining-time-first scheduling.

66.The SJF algorithm is a special case of the general priority-scheduling algorithm.

67.A major problem with priority scheduling algorithm is starvation / indefinite blocking.

68.A priority scheduling algorithm leaves some low priority processes waiting indefinitely for the CPU.

68Process Management, Thread Scheduling

Page 69: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Fill in the Blanks

69.A solution to the problem of indefinite blockage of low priority processes is aging.

70.Aging is a technique of gradually increasing the priority of processes that wait in the system for a long time.

71.The round robin scheduling algorithm is designed for time sharing systems.

72.The round robin scheduling algorithm is preemptive.

73.A multilevel queue scheduling algorithm partitions the ready queue into several separate queues.

74.A multilevel feedback queue scheduling allows a process to move between queues.

69Process Management, Thread Scheduling|<<

Page 70: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

• Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process– unbounded-buffer places no practical limit on the

size of the buffer– bounded-buffer assumes that there is a fixed

buffer size

Producer-Consumer Problem

Page 71: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

– Shared data#define BUFFER_SIZE 10typedef struct {

. . .} item;

item buffer[BUFFER_SIZE];int in = 0;int out = 0;

Bounded-Buffer – Shared-Memory Solution

Page 72: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

producer

• while (true) { /* Produce an item */

• while (((in = (in + 1) % BUFFER SIZE count) == out)• ; /* do nothing -- no free buffers */• buffer[in] = item;• in = (in + 1) % BUFFER SIZE;• }

Page 73: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

consumer

• while (true) {• while (in == out)• ; // do nothing -- nothing to consume

• // remove an item from the buffer• item = buffer[out];• out = (out + 1) % BUFFER SIZE;• return item;• }

Page 74: UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process ConceptsConcepts Chapter 4: Multithread Programming Threads Chapter 5:

Communication model