process description and control
DESCRIPTION
Process Description and control. G.Anuradha (Referred from william stallings and galvin 8 th edition). Contents. Introduction Process states Process description Process control. Introduction. OS must interleave the execution of multiple processes to maximize processor utilization - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/1.jpg)
Process Description and control
G.Anuradha(Referred from william stallings and
galvin 8th edition)
![Page 2: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/2.jpg)
Contents
• Introduction• Process states• Process description• Process control
![Page 3: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/3.jpg)
Introduction
• OS must interleave the execution of multiple processes to maximize processor utilization
• Proper allocation of resources and avoidance of deadlocks
• Interprocess communications
![Page 4: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/4.jpg)
Process states
• What is it?• A two-state Process model• Creation and termination of processes• Five state model• Suspended processes
![Page 5: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/5.jpg)
What is it?• An operating system executes a variety of programs:
– Batch system – jobs– Time-shared systems – user programs or tasks
• Textbook uses the terms job and process almost interchangeably• Process – a program in execution; process execution must
progress in sequential fashion• A process includes:
– program counter – stack– data section
![Page 6: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/6.jpg)
Trace of the Process
• The behavior of an individual process is shown by listing the sequence of instructions that are executed
• This list is called a Trace• Dispatcher is a small program which switches
the processor from one process to another
![Page 7: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/7.jpg)
Process Execution
• Consider three processes being executed
• All are in memory (plus the dispatcher)
• Lets ignore virtual memory for this.
![Page 8: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/8.jpg)
Trace from the processes point of view:
• Each process runs to completion
![Page 9: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/9.jpg)
Trace from Processors point of view
TimeoutI/O
TimeoutTimeout
![Page 10: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/10.jpg)
A Two-State Process Model
![Page 11: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/11.jpg)
Queuing Diagram
Etc … processes moved by the dispatcher of the OS to the CPU then back to the queue until the task is competed
![Page 12: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/12.jpg)
Review till now
• What is a Trace?• What is a Dispatcher?• What are the two states of a two state process
model?
![Page 13: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/13.jpg)
Creation and Termination of Processes
• Life of a process is bounded by its creation and termination
• When a new process is added– OS builds data structures– Allocates address space in main memory
![Page 14: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/14.jpg)
Process Creation
• The OS builds a data structure to manage the process
• Traditionally, the OS created all processes– But it can be useful to let a running process create
another• This action is called process spawning– Parent Process is the original, creating, process– Child Process is the new process
![Page 15: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/15.jpg)
Reasons for process creation
![Page 16: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/16.jpg)
Process Termination
• There must be some way that a process can indicate completion.
• This indication may be:– A HALT instruction generating an interrupt alert to
the OS.– A user action (e.g. log off, quitting an application)– A fault or error– Parent process terminating
![Page 17: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/17.jpg)
Process Termination
![Page 18: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/18.jpg)
Five State Model
![Page 19: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/19.jpg)
Five State Process Model
• Running: process that is currently being executed• Ready: process that is prepared to execute when
given the opportunity• Blocked: process that is waiting for some event to
occur • New: process that has not yet been loaded into
main memory• Exit: process that is released because its halted
or its aborted
![Page 20: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/20.jpg)
Process model contd…
• In New state a process is defined which happens in 2 stages– OS gives a Id– Tables needed are allocated and built
• While in new state the program remains in secondary storage
![Page 21: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/21.jpg)
Process model contd…
• Termination moves the process to exit state• Exit also occurs in two stages– The tables and other information associated with
job are Temporarily preserved by OS– Once the utility programs extracts the needed
information the OS no longer maintains any data and the process is deleted from the system.
![Page 22: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/22.jpg)
Events that lead to state transition• NullNew: new process is created• Newready : Admit – When OS is prepared to take an additional
process• ReadyRunning: Dispatch When OS has to select a process it selects
one from the ready state• Running exit : Release – When process is completed or is aborted• RunningReady: Time-out or when the process is preempted• Running Blocked: EventWait – Waiting for I/O or any other system
call which is performed by the OS• BlockedReady :Event Occurs• ReadyExit: In some systems a parent may terminate a child process at
any time(not shown in diagram)• Blocked exit:
![Page 23: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/23.jpg)
Single blocked queue diagram
![Page 24: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/24.jpg)
Multiple blocked queues
![Page 25: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/25.jpg)
Suspended Processes
• What is it?• Need for Swapping• Other uses of suspension
![Page 26: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/26.jpg)
Need for Swapping
• The I/O takes more time than processor execution• Even with multiprogramming with lots of I/O
operations the execution speed of processor comes down
• This can be avoided by expanding the main memory. But– Cost of main memory is more – Larger memory results in larger processes not more
processes• Second solution is Swapping
![Page 27: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/27.jpg)
Swapping
• Swapping is moving part or all of a process from main memory to disk
• This happens when none of the processes in main memory are in Ready state
• In the disk the processes are in a suspend queue – which has existing processes that has been kicked out of main memory
• After this the OS brings some other process in the suspend queue or some new process
• With swapping we have an additional state-suspend state
![Page 28: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/28.jpg)
State transition diagram with single suspend state
![Page 29: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/29.jpg)
Need for suspend states
• When swapping takes place the OS can decide to get the process from the new state or from suspend state. This can include more states
• Ready: Process in main memory and available for execution
• Blocked: Process in main memory and awaiting an event• Blocked/Suspend: Process in secondary memory and
awaiting an event• Ready/Suspend: Process in secondary memory but is
available for execution
![Page 30: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/30.jpg)
Process Description
• What is it?• OS control Structures
– Memory tables– I/O tables– File tables– Process tables
• Process Control Structures– Process Location– Process Attributes– Processor state information– Process Control Block
![Page 31: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/31.jpg)
What is Process Description?OS is an entity that manages the use of system resources by processes
What information does the OS need to control processes and manage resources for them?Current status of each process and resourceHow the OS does it? Maintains tables of each entity it’s managing
![Page 32: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/32.jpg)
General Structure of OS control tables
![Page 33: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/33.jpg)
Process Control Structures
• For managing and control a process the OS should know– Where the process is located– Attributes of the process that are necessary for its
management (Process ID, Process State, Location in Memory)
![Page 34: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/34.jpg)
Process Image
![Page 35: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/35.jpg)
Process Location
• Location of a process image will depend on the memory management scheme
• Process image is maintained as a contiguous or continuous block of memory
• This block is maintained in the disk and OS needs to know the location in the disk
• For OS to manage the process at least a small portion of its image must be maintained in main memory
• Modern OS uses memory management schemes like paging or segmentation for bringing only a portion of process image in the main memory
• These details should also be stored in the process table
![Page 36: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/36.jpg)
Process Control Block
• Information about a process is stored in a Process control Block(PCB)
• PCB information is grouped into 3 heads– Process Identification– Process state information– Process Control information
![Page 37: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/37.jpg)
Process Identification
• Identifier of this process• Identifier of the process that created this
process (parent Process)• User Identifier
![Page 38: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/38.jpg)
Processor State Information
![Page 39: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/39.jpg)
Process Control Information
![Page 40: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/40.jpg)
Role of PCB
• It is the most important data structure in an OS• Each PCB contains all of the information about a
process that is needed by the OS• The blocks are read and/or modified by every
module in the OS including– Scheduling– Resource allocation– Interrupt processing– Performance monitoring and analysis
![Page 41: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/41.jpg)
Role of PCB Contd…
• Direct access to PCB acts as a threat to its protection– A bug in a single routine could damage PCB which
could destroy the ability to manage other processes
– A design change in PCB could affect a number of modules in the OS
• Solution is to use a handler routine to protect the PCB
![Page 42: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/42.jpg)
Process Control
• Modes of execution:-– User mode-less privileged mode– Kernel mode- more privileged mode
• Reasons for two modes– Protect the OS, and OS tables like PCB from interference by
user programs• In the kernel mode, the software has complete control of
the processor and its instructions, registers, and memory• Program Status Word (PSW) indicates the mode of
execution
![Page 43: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/43.jpg)
Steps in Process Creation1. Assign a unique PID to the new process:- entry is made to the
primary process table2. Allocate space for the process:-all elements in the process
image like, user address space, user stack are to be set3. Initialize PCB
1. Process ID portion will contain the IDs2. Processor State Information portion will be initialized to
zero(mostly)3. Process Control Information is initialized based on standard default
values plus attributes requested for this process
4. Set Appropriate linkages5. Create or expand other data structures
![Page 44: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/44.jpg)
Process Control Block (PCB)Information associated with each process• Process state• Program counter: Address of the next instruction to be
executed• CPU registers: State information which must be saved
when an interrupt occurs.• CPU scheduling information: process priority, pointers to
scheduling queues, and other scheduling parameters. • Memory-management information: base and limit
registers, base table and segment table• Accounting information: time limits, account and process
numbers etc• I/O status information: list of I/O devices allocated to the
process a list of open files and so on
![Page 45: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/45.jpg)
Process Control Block (PCB)
![Page 46: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/46.jpg)
CPU Switch From Process to Process
![Page 47: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/47.jpg)
QuizAcross2.complete control of processor6.less priviledged mode7.one process creating another8.List of Instructions
Down1.process waiting for input output operation3.Program to switch processor from one process to another process4.moving part or all process from main memory to disk5.Program in execution
![Page 48: Process Description and control](https://reader036.vdocument.in/reader036/viewer/2022062321/568130e0550346895d96f0ab/html5/thumbnails/48.jpg)
Quiz answers