A. Frank - P. Weisberg Operating Systems Process Scheduling and Switching.

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

Processes Management.
Chapter 3 Process Description and Control
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Objectives Understand Process concept Process scheduling Creating.
CMPT 300: Operating Systems I Ch 3: Processes Dr. Mohamed Hefeeda
1 When to Switch Processes 3 triggers –System call, Interrupt and Trap System call –when a user program invokes a system call. e.g., a system call that.
CSSE Operating Systems
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
UNIX Process Creation Every process, except process 0, is created by the fork() system call fork() allocates entry in process table and assigns a unique.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
Process Description and Control A process is sometimes called a task, it is a program in execution.
1 Lecture 10: Uniprocessor Scheduling. 2 CPU Scheduling n The problem: scheduling the usage of a single processor among all the existing processes in.
Process Description and Control
CE Operating Systems Lecture 5 Processes. Overview of lecture In this lecture we will be looking at What is a process? Structure of a process Process.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Chapter 41 Processes Chapter 4. 2 Processes  Multiprogramming operating systems are built around the concept of process (also called task).  A process.
Exec Function calls Used to begin a processes execution. Accomplished by overwriting process imaged of caller with that of called. Several flavors, use.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
8-Sep Operating Systems Yasir Kiani. 8-Sep Agenda for Today Review of previous lecture Process scheduling concepts Process creation and termination.
Chapter 2 Processes Processes Topics Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Computer Studies (AL) Operating System Process Management - Process.
Processes – Part I Processes – Part I. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Review on OSs Upon brief introduction of OSs,
11/13/20151 Processes ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original.
Process Description and Control
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
Processes Dr. Yingwu Zhu. Process Concept Process – a program in execution – What is not a process? -- program on a disk - a process is an active object,
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Q:Process Stateu 有哪些 ? 何種情形下會做 transition? As a process executes, it.
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
Processes & Threads Introduction to Operating Systems: Module 5.
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 8 Processes II Read Ch.
Operating System Components) These components reflect the services made available by the O.S. Process Management Memory Management I/O Device Management.
Uniprocessor Scheduling Chapter 9 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,
Processes and threads.
Chapter 3: Processes.
Chapter 3: Process Concept
Topic 3 (Textbook - Chapter 3) Processes
Operating Systems (CS 340 D)
Sujata Ray Dey Maheshtala College Computer Science Department
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 3: Process-Concept
Chapter 3: Processes.
Intro to Processes CSSE 332 Operating Systems
Operating Systems (CS 340 D)
Chapter 3: Processes.
Process Virtualization. Process Process is a program that has initiated its execution. A program is a passive entity; whereas a process is an active entity.
Operating Systems CPU Scheduling.
Lecture 2: Processes Part 1
Operating Systems Lecture 6.
Process & its States Lecture 5.
Mid Term review CSC345.
Chapter 3: Processes.
Sujata Ray Dey Maheshtala College Computer Science Department
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Chapter 3: Processes.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Chapter 6: Scheduling Algorithms Dr. Amjad Ali
Chapter 3: Processes Process Concept Process Scheduling
Presentation transcript:

A. Frank - P. Weisberg Operating Systems Process Scheduling and Switching

2 A. Frank - P. Weisberg Processor Scheduling Maximize CPU use, quickly switch processes onto CPU for time sharing. Process scheduler selects among available processes for next execution on CPU. Maintains scheduling queues of processes: –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.

3 A. Frank - P. Weisberg Types of Schedulers 1.Long-term scheduler (jobs scheduler) – selects which programs/processes should be brought into the ready queue. 2.Medium-term scheduler (emergency scheduler) – selects which job/process should be swapped out if system is loaded. 3.Short-term scheduler (CPU scheduler) – selects which process should be executed next and allocates CPU.

4 A. Frank - P. Weisberg Long-Term Scheduling Determines which programs are admitted to the system for processing. Controls the degree of multiprogramming. If more processes are admitted: –less likely that all processes will be blocked – better CPU usage. –each process has less fraction of the CPU. Long-term scheduler strives for good process mix.

5 A. Frank - P. Weisberg Short-Term Scheduling Determines which process is going to execute next (also called CPU scheduling). The short term scheduler is also known as the dispatcher (which is part of it). Is invoked on a event that may lead to choose another process for execution: –clock interrupts –I/O interrupts –operating system calls and traps –signals

6 A. Frank - P. Weisberg Long/Short-Term Scheduling Long- term Short- term

7 A. Frank - P. Weisberg Aspects of Schedulers Long-term scheduler is invoked very infrequently (seconds, minutes)  (may be slow). The long-term scheduler controls the degree of multiprogramming. Short-term scheduler is invoked very frequently (milliseconds)  (must be fast). Processes can be described as either: –I/O-bound process – spends more time doing I/O than computations, many short CPU bursts. –CPU-bound process – spends more time doing computations; few very long CPU bursts.

8 A. Frank - P. Weisberg Medium-Term Scheduling So far, all processes have to be (at least partly) in main memory. Even with virtual memory, keeping too many processes in main memory will deteriorate the system’s performance. The OS may need to swap out some processes to disk, and then later swap them back in. Swapping decisions based on the need to manage multiprogramming.

9 A. Frank - P. Weisberg Schematic View of Swapping

10 A. Frank - P. Weisberg Dynamics of Swapping A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution Backing store – fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images. Roll out, roll in – swapping variant used for priority-based scheduling algorithms; lower-priority process is swapped out so higher-priority process can be loaded and executed. Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory swapped. Modified versions of swapping are found on many systems (i.e., UNIX, Linux, and Windows). System maintains a ready queue of ready-to-run processes which have memory images on disk

11 A. Frank - P. Weisberg Swapping Example

12 A. Frank - P. Weisberg Addition of Medium Term Scheduling Long- term Short- term Medium- term

13 A. Frank - P. Weisberg Support for Swapping The OS may need to suspend some processes, i.e., to swap them out to disk and then swap them back in. We add 2 new states: –Blocked Suspend: blocked processes which have been swapped out to disk. –Ready Suspend: ready processes which have been swapped out to disk.

14 A. Frank - P. Weisberg A Seven-state Process Model

15 A. Frank - P. Weisberg New state transitions Blocked – > Blocked Suspend –When all processes are blocked, the OS will make room to bring a ready process in memory. Blocked Suspend – > Ready Suspend –When the event for which it has been waiting occurs (state info is available to OS). Ready Suspend – > Ready –when no more ready processes in main memory. Ready – > Ready Suspend (unlikely) –When there are no blocked processes and must free memory for adequate performance.

16 A. Frank - P. Weisberg Classification of Scheduling Activity

17 A. Frank - P. Weisberg Another view of the 3 levels of scheduling

18 Queuing Diagram for Scheduling

19 A. Frank - P. Weisberg Dispatcher (short-term scheduler) Is an OS program that moves the processor from one process to another. It prevents a single process from monopolizing processor time. It decides who goes next according to a scheduling algorithm. The CPU will always execute instructions from the dispatcher while switching from process A to process B.

20 A. Frank - P. Weisberg Process Scheduling Queues Process queue – set of all processes in the system. Ready queue – set of 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.

21 A. Frank - P. Weisberg A Queuing Discipline When event n occurs, the corresponding process is moved into the ready queue

22 A. Frank - P. Weisberg Ready Queue and various I/O Device Queues

23 A. Frank - P. Weisberg Process Switch

24 A. Frank - P. Weisberg When to Switch a Process? A process switch may occur whenever the OS has gained control of CPU. i.e., when: –Supervisor Call explicit request by the program (example: file open) – the process will probably be blocked. –Trap an error resulted from the last instruction – it may cause the process to be moved to terminated state. –Interrupt the cause is external to the execution of the current instruction – control is transferred to Interrupt Handler.

25 A. Frank - P. Weisberg Reasons for Process Switch

26 A. Frank - P. Weisberg Context Switch When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process. This is called context switch. Context of a process represented in the PCB. The time it takes is dependent on hardware support. Context-switch time is overhead; the system does no useful work while switching.

27 A. Frank - P. Weisberg Context switch between processes (1)

28 A. Frank - P. Weisberg Context switch between processes (2)

29 A. Frank - P. Weisberg Steps in Context Switch Save context of processor including program counter and other registers. Update the PCB of the running process with its new state and other associate information. Move PCB to appropriate queue – ready, blocked, Select another process for execution. Update PCB of the selected process. Restore CPU context from that of the selected process.

30 A. Frank - P. Weisberg Example of Context Switch p1p2 p3 kernelI/O scheduler device driver { } scheduler } } device driver { scheduler } I/O request Time slice exceeded Interrupt

31 A. Frank - P. Weisberg Mode Switch It may happen that an interrupt does not produce a context switch. The control can just return to the interrupted program. Then only the processor state information needs to be saved on stack. This is called mode switch (user to kernel mode when going into Interrupt Handler). Less overhead: no need to update the PCB like for context switch.