07/10/2020 1
Lecture 6
Chapter 2
Processes and Threads
discover yourself
1.Processes
2.Threads
3.Inter-Process Communication
(IPC)
4.Scheduling
Contents
discover yourself
07/10/2020 3
Processes
Processes
Difference between Process and Program
Program
A set of instruction to solve the problem.
Process
A program in execution.
discover yourself
Processes
Processes
Difference between Process and Program
Baking a Birthday Cake
1- Baker - A person who will bake the cake 2- Recipe – Method to bake the cake
3- Ingredients – Inputs/things to bake the cake
Here baker acts as a processor (CPU) Recipe acts as a program
Ingredients acts as an input data
So, process is an activity consisting of our baker reading the recipe, fetching the ingredients and baking the cake.
discover yourself
07/10/2020 5
The Process Model The Process Model
4 programs in the
memory Only one program is active at once
In Process model, all software on the computer is organized into a number of sequential processes. A process includes PC, registers, and variables. In reality, the CPU switches back and forth among processes. (The rapid switching back and forth is called multiprogramming).
discover yourself
Process Creation – System Initialization Process Creation – System Initialization
1. Foreground processes
Interact with users and perform work for them
2. Background processes
Not associated with users but have some specific functions.
discover yourself
07/10/2020 7
Process Creation
Process Creation
Principal events that cause process creation
1.
System initialization
2.
Execution of a process creation system
3.
User request to create a new process
4.
Initiation of a batch job
discover yourself
Process Creation – System Initialization Process Creation – System Initialization
Background processes in XP &
discover yourself
07/10/2020 9 Process Creation – System Initialization
Process Creation – System Initialization
Foreground
Processes
discover yourself
Process Creation – System Initialization Process Creation – System Initialization
discover yourself
07/10/2020 11
Process Creation – Execution of a process creation system call Process Creation – Execution of a process creation system call
Running process will issue some system calls to create one or more new processes.
e.g. Large amount of data fetched over a network. User requests of a file be printed.
discover yourself
Process Creation – a user request to create a new process Process Creation – a user request to create a new process
These actions starts a new process and runs the selected programs in it.
discover yourself
07/10/2020 13 Process Creation – Batch system process
Process Creation – Batch system process
discover yourself
Process Creation – Batch system process Process Creation – Batch system process
discover yourself
07/10/2020 15 Process Creation – Batch system process
Process Creation – Batch system process
discover yourself
Process Termination Process Termination
Conditions which terminate processes
1. Normal exit
2. Error exit
3. Fatal error
4. Killed by another process
discover yourself
07/10/2020 17
Process Termination Process Termination
Normal Exit
1. Processes terminate because they have done their work.
This is called normal exit.
2. e.g. Compiler compile the program. This call is EXIT in
UNIX and EXIT process in Windows.
discover yourself
Process Termination – Normal Exit Process Termination – Normal Exit
Example how process is terminated in Windows environment
discover yourself
07/10/2020 19 Process Termination – Normal Exit
Process Termination – Normal Exit
discover yourself
Process Termination – Normal Exit Process Termination – Normal Exit
discover yourself
07/10/2020 21
Process Termination – Error Exit Process Termination – Error Exit
Process terminates when error is introduced in it.
If user types the command
cc prog1.c
to compile the program prog1.c and no such file exists, the
compiler simply exits.
discover yourself
Process Termination – Error Exit Process Termination – Error Exit
Disk Operating System (DOS)
discover yourself
07/10/2020 23
Process Termination – Error Exit Process Termination – Error Exit
Windows Environment
discover yourself
Process Termination – Error Exit Process Termination – Error Exit
Windows Environment
discover yourself
07/10/2020 25
Process Termination – Fatal Error Process Termination – Fatal Error
In computing, a fatal error or fatal exception error is an error that causes a program to abort and may therefore return the user to the operating system. When this happens, data that the program was processing may be lost. This is an error caused by the process,
often due to the program bug.
e.g.
1.Executing an illegal instruction
2.Referencing non-existent memory location
3.Dividing the number by ZERO. (Executio
n Error)
discover yourself
Process Termination – Fatal Error Process Termination – Fatal Error
discover yourself
07/10/2020 27
Process Termination – Fatal Error Process Termination – Fatal Error
discover yourself
Process Termination – Fatal Error Process Termination – Fatal Error
discover yourself
07/10/2020 29
Process Termination – Killed by another process Process Termination – Killed by another process
1. Process executes a system call telling the OS to kill
some other process. In UNIX this call is KILL and
TERMINATE process in Windows.
discover yourself
Two States Transition Diagram
discover yourself
07/10/2020 31
Five States Process Model
Running
The process that is currently being executed
Ready
A process that is prepare to execute when given the opportunity
Blocked
A process that cannot execute until some event occur, such as I/O operations.
New
A process that has just been created
Exit
A process that has been released from the pool of executable processes by the OS
discover yourself
Five States Process Model
discover yourself
inspire posterity
New Ready Running Exit
Blocked Admit
Event Occurs
Dispatch Release
Time-out
07/10/2020 33
discover yourself
inspire posterity
Single Blocked Queue
discover yourself
inspire posterity
Admit Ready Queue Dispatch Time-out Release ProcessorEvent 1 Wait
Event 1 Queue Event 1
Occurs
Event 2 Wait Event 2
Occurs
07/10/2020 35 New Ready: The OS will move a process from new state to the ready state
Ready Running: The OS will choose one of the process from the ready state. This is the job of dispatcher or scheduler.
Running Exit: The running process is terminated by the OS, if the process indicates that it has completed his job.
Running Ready: When running process has reached max. allowable time.
Running Blocked: A process is put in the blocked state if it requests something i.e. request a resource such as file, I/O operations.
Blocked Ready: A process in the blocked state is moved to the ready state when the event for which it has been waiting occurs.