Chapter 4 Processes n Process Concept n Process

  • Slides: 16
Download presentation
Chapter 4: Processes n Process Concept n Process Scheduling n Types of shedulars n

Chapter 4: Processes n Process Concept n Process Scheduling n Types of shedulars n Process states n 2 -state model n 5 -state model n 6 -state model n 7 -state model n Operations on Processes Operating System Concepts 4. 1 Silberschatz, Galvin and Gagne 2002

Process Concept n An operating system executes a variety of programs: F Batch system

Process Concept n An operating system executes a variety of programs: F Batch system – jobs F Time-shared systems – user programs or tasks n Textbook uses the terms job and process almost interchangeably. n Process – a program in execution; process execution must progress in sequential fashion. n Program: F Resides on disk; passive entity n Peocess F Resides in memory, running on or waiting for cpu; active entiry Operating System Concepts 4. 2 Silberschatz, Galvin and Gagne 2002

Process Execution n Execution sequence FFetch FDecode FExecute FWrite results FSet PC to next

Process Execution n Execution sequence FFetch FDecode FExecute FWrite results FSet PC to next instruction FRepeat Operating System Concepts 4. 3 Silberschatz, Galvin and Gagne 2002

Process Components n A process includes: F CPU state (program counter and other control

Process Components n A process includes: F CPU state (program counter and other control registers) F code section F data section F Stack (parameters and local variables for sub-functions) F Heap (space for dynamically allocated memory) F Environment (command line parameters) F Process control block (PCB: a kernel data structure) Operating System Concepts 4. 4 Silberschatz, Galvin and Gagne 2002

Process control block n A data structure which contains all the information about a

Process control block n A data structure which contains all the information about a running process. n Helps OS to manage processes. n Used in context switching. Operating System Concepts 4. 5 Silberschatz, Galvin and Gagne 2002

Basic Types of Process n CPU Bound processes F Which spend more time on

Basic Types of Process n CPU Bound processes F Which spend more time on cpu and less on I/O e. g. running a mathematical computation like matrix multiplication, running simulations to process given data etc. n I/O Bound processes F Which spend more time on I/O and less on CPU e. g. word processors, data entry software etc. Operating System Concepts 4. 6 Silberschatz, Galvin and Gagne 2002

2 -State Process Model Dispatch Enter Exit Not Running Pause Wait for an I/O

2 -State Process Model Dispatch Enter Exit Not Running Pause Wait for an I/O Operating System Concepts 4. 7 Silberschatz, Galvin and Gagne 2002

Queuing Diagram (2 -State Process Model) • Queuing structure for a two state process

Queuing Diagram (2 -State Process Model) • Queuing structure for a two state process model is: Limitations • If all processes in the queue are always ready to execute only then the above queuing discipline will work • But it may also be possible that some processes in the queue are ready to execute, while some are waiting for an I/O operation to complete • So the dispatcher has to scan the list of processes looking for the process that is not blocked and is there in the queue for the longest CMP 320 PUCIT Arif Butt 12/29/2021 4. 8 8 Silberschatz, Galvin and Gagne 2002

5 -State Model • A process may not be in exactly two states when

5 -State Model • A process may not be in exactly two states when there are more than one processes. For example, when one process has completed its I/O, its can’t get back to CPU because another process may be using it. So this process is ready but can’t run. • Also process may be blocked for more than one reasons like: • • • Operating System Concepts A process may be waiting for an event to occur; e. g. a process has created a child process and is waiting for it to return the result A process may be waiting for a resource which is not available at this time Process has gone to sleep for some time 4. 9 Silberschatz, Galvin and Gagne 2002

Process State n As a process executes, it changes state F new: The process

Process State n As a process executes, it changes state F new: The process is being created. F running: Instructions are being executed. F waiting: The process is waiting for some event to occur e. g. I/O completion or any other signal to come. F ready: The process is waiting to be assigned CPU. F terminated: The process has finished execution. Operating System Concepts 4. 10 Silberschatz, Galvin and Gagne 2002

Process Scheduling Queues n Job queue – set of all processes in the system.

Process Scheduling Queues n Job queue – set of all processes in the system. n Ready queue – set of all processes residing in main memory, ready and waiting to execute. n Device queues – set of processes waiting for an I/O device. n Process migration between the various queues. Operating System Concepts 4. 11 Silberschatz, Galvin and Gagne 2002

Queuing Diagram (Using 2 -Queues Limitation: When an event occurs the dispatcher would have

Queuing Diagram (Using 2 -Queues Limitation: When an event occurs the dispatcher would have to cycle through the entire Blocked Queue to see which process is waiting for that event. This can cause huge overhead when there may be 100’s or 1000’s of processes 12/29/2021 CMP 320 PUCIT Arif Butt 4. 12 12 Silberschatz, Galvin and Gagne 2002

Ready Queue And Various I/O Device Queues Operating System Concepts 4. 13 Silberschatz, Galvin

Ready Queue And Various I/O Device Queues Operating System Concepts 4. 13 Silberschatz, Galvin and Gagne 2002

Representation of Process Scheduling Operating System Concepts 4. 14 Silberschatz, Galvin and Gagne 2002

Representation of Process Scheduling Operating System Concepts 4. 14 Silberschatz, Galvin and Gagne 2002

6 -State Process Model (one suspended state) Limitation: This only allows processes which are

6 -State Process Model (one suspended state) Limitation: This only allows processes which are blocked to be swapped out. What if there is no blocked process but we still need to free up memory? Solution: Add another state Ready Suspended and swap out a process from the 12/29/2021 CMP 320 PUCIT Arif Butt ready state 4. 15 Silberschatz, Galvin and Gagne 2002

7 -State Process Model 12/29/2021 CMP 320 PUCIT Arif Butt 4. 16 (two suspended

7 -State Process Model 12/29/2021 CMP 320 PUCIT Arif Butt 4. 16 (two suspended state) Silberschatz, Galvin and Gagne 2002