Process
Process
Process Concept
• Process is a Program in execution.
• A process defines the fundamental unit of computation for the computer.
• A process can run to completion only when all requested resources have been
allocated to the process.
• Two or more processes could be executing the same program, each using their
own data and resources.
Process Concept
Multiple parts of a process
◦ The program code, also called text section
◦ Current activity including program counter
◦ Stack containing temporary data
◦ Function parameters, return addresses, local variables
◦ Data section containing global variables
◦ Heap containing memory dynamically allocated during run time
Process and Program
• Process is a dynamic entity that is a program in execution, while Program is a
static entity made up of program statement.
• A process is a sequence of information executions, while Program contains the
instructions.
• Process exists in a limited span of time, while a program exists at single place in
space and continues to exist.
• Two or more processes could be executing the same program, each using their
own data and resources.
Process States
• When process executes, it changes state. Process state is defined as the current
activity of the process.
• A process exists in one of the five states:
o New: A process that just been created.
o Ready: Ready processes are waiting to have the processor allocated to them by the
operating system so that they can run.
o Running: The process that is currently being executed. A running process possesses all the
resources needed for its execution, including the processor.
o Waiting: A process that can not execute until some event occurs such as the completion
of an I/O operation. The running process may become suspended by invoking an I/O
module.
o Terminated: A process that has been released from the pool of executable processes by
the operating system.
Process States
Process Control Block
Each process contains the process control block (PCB).
PCB is the data structure used by the operating
system.
Operating system groups all information that it needs
about particular process.
Scheduling Queues
Schedulers
Schedulers are of three types.
1. Long Term Scheduler
2. Short Term Scheduler
3. Medium Term Scheduler
Long term scheduler
• It is also called job scheduler.
• Long term scheduler determines which programs are admitted to the system
for processing.
• Job scheduler selects processes from the queue and loads them into memory
for execution.
• The primary objective of the job scheduler is to provide a balanced mix of jobs,
such as I/O bound and processor bound. It also controls the degree of
multiprogramming.
Short term scheduler
• It is also called CPU scheduler.
• It is the change of ready state to running state of the process.
• CPU scheduler selects from among the processes that are ready to execute and
allocates the CPU to one of them.
• Short term scheduler also known as dispatcher.
• Short term scheduler is faster than long tern scheduler.
Medium term Scheduler
• Medium term scheduling is part of the swapping function.
• It reduces the degree of multiprogramming.
• The medium term scheduler is in charge of handling the swapped out-
processes.
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 via a context switch
• Context of a process represented in the PCB
• Context-switch time is overhead; the system does no useful work while
switching
◦ The more complex the OS and the PCB the longer the context switch
Operations on Processes
System must provide mechanisms for:
◦ process creation,
◦ process termination
Process Creation
Parent process create child processes, which, in turn create other processes,
forming a tree of processes
Generally, process identified and managed via a process identifier (pid)
Resource sharing options
◦ Parent and children share all resources
◦ Children share subset of parent’s resources
◦ Parent and child share no resources
Execution options
◦ Parent and children execute concurrently
◦ Parent waits until children terminate
Process Termination
• Process executes last statement and then asks the operating system to delete
it using the exit() system call.
• Returns status data from child to parent (via wait())
• Process’ resources are deallocated by operating system
•Synchronization
• Blocking send
• Nonblocking send
• Blocking receive
• Nonblocking receive
•Buffering
• Zero capacity
• Bounded capacity
• Unbounded capacity
Thread
A thread is called a light weight process.
A thread is a flow of execution through the process code, with its
own program counter, system registers and stack.
Threads are a popular way to improve application performance
through parallelism.
Each thread belongs to exactly one process and no thread can exist
outside a process.
Single-threaded and Multi-threaded processes
Benefits of Multithreaded Environment
Responsiveness
Resource Sharing
Economy
Scalability
Types of Thread
Thread is implemented in two ways :
1. User Level
2. Kernel Level
User Level Thread
All of the work of thread management is done by the application and the
kernel is not aware of the existence of threads.
The thread library contains code for creating and destroying threads.
The application begins with a single thread and begins running in that
thread.
Kernel Level Threads
Thread management is done by the Kernel.
No thread management code in the application area.
Kernel threads are supported directly by the operating system.
The Kernel performs thread creation, scheduling and management in
Kernel space.
Kernel threads are generally slower to create and manage than the
user threads.
User Level vs Kernel Level Threads
S.No. User Level Threads Kernel Level Thread
1 User level thread are faster to create and Kernel level thread are slower to create and
manage. manage.
2 Implemented by a thread library at the user Operating system support directly to Kernel
level. threads.
3 User level thread can run on any operating Kernel level threads are specific to the operating
system. system.
4 Multithread application cannot take Kernel routines themselves can be multithreaded.
advantage of multiprocessing.
Advantages of Thread
1. Thread minimize context switching time.
2. Use of threads provides concurrency within a process.
3. Efficient communication.
4. Economy- It is more economical to create and terminate threads than processes.
5. Utilization of multiprocessor architectures– The benefits of multithreading can be greatly
increased in a multiprocessor architecture.
Multithreading Models
Some operating system provide a combined user level thread and Kernel level thread
facility.
Solaris is a good example of the combined approach.
In a combined system, multiple threads within the same application can run in parallel
on multiple processors.
Multithreading models are of three types:
1. Many to many relationship.
2. Many to one relationship.
3. One to one relationship.
Many to Many Model