Module 4: Processes

Download Report

Transcript Module 4: Processes

Chapter 4: Processes
 Process Concept
 Process Scheduling
 Types of shedulars
 Process states
 2-state model
 5-state model
 6-state model
 7-state model
 Operations on Processes
Operating System Concepts
4.1
Silberschatz, Galvin and Gagne 2002
Process Concept
 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.
 Program:
 Resides on disk; passive entity
 Peocess
 Resides in memory, running on or waiting for cpu; active
entiry
Operating System Concepts
4.2
Silberschatz, Galvin and Gagne 2002
Process Execution
 Execution sequence
Fetch
Decode
Execute
Write results
Set PC to next instruction
Repeat
Operating System Concepts
4.3
Silberschatz, Galvin and Gagne 2002
Process Components
 A process includes:
 CPU state (program counter and other control registers)
 code section
 data section
 Stack (parameters and local variables for sub-functions)
 Heap (space for dynamically allocated memory)
 Environment (command line parameters)
 Process control block (PCB: a kernel data structure)
Operating System Concepts
4.4
Silberschatz, Galvin and Gagne 2002
Process control block
 A data structure which
contains all the information
about a running process.
 Helps OS to manage
processes.
 Used in context switching.
Operating System Concepts
4.5
Silberschatz, Galvin and Gagne 2002
Basic Types of Process
 CPU Bound processes
 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.
 I/O Bound processes
 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
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 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
CMP320 PUCIT Arif Butt
4/1/2016
4.8
8
Silberschatz, Galvin and Gagne 2002
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
 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
e.g. I/O completion or any other signal to come.
 ready: The process is waiting to be assigned CPU.
 terminated: The process has finished execution.
Operating System Concepts
4.10
Silberschatz, Galvin and Gagne 2002
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.
 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 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
4/1/2016
CMP320 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 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 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
ready state
4/1/2016
CMP320 PUCIT Arif Butt
4.15
Silberschatz, Galvin and Gagne 2002
7-State Process Model
4/1/2016
CMP320 PUCIT Arif Butt
4.16
(two suspended state)
Silberschatz, Galvin and Gagne 2002