Chapter 2.process Management
Chapter 2.process Management
Process Management
3.0.Introduction
1.A running instance of program is called as process.A process is a smallest
unit of work that is scheduled by the OS.
2.A process needs resources,such as CPU time,memory,files and I/O devices
to accomplish its task.These resources are allocated either when the program
is
created or when it is executing.
3.A user uses processes to achieve execution of programs in a sequential or
concurrent manner as desired.
4.Process management is the fundamental task of any modern OS.The OS
must allocate resources to processes,enable processes to share and exchange
information,protect the resources of each process from other processes and
enable synchronization among processes.
5.To meet these requirnments,the OS must maintain a data structure for each
process,which describes the state and resource ownership of that process,and
which enables the OS to exert control over each process.
3.1.Process
1.A process is defined as ,”an entity which represents the basic unit of work to
be implemented in the system”.
2.A process is defined as, ”Program under execution,which competes for the
CPU time and other resources.”
3.A process is a program in execution.Process is also called as job,task and
unit of work.
4.The execution of a process must progress in a sequential fashion.That is ,at
any time ,at most one instruction is executed on behalf of the process.
5.A process is an instance of an executing program ,including the current
values of the program counter ,registers and variables.
6.Logically each process has its seprate virtual CPU.in actual,the real CPU
switches from one process to an other.
7.A process is an activity and it has a program,input,output and a state.
• Each process has Following sections:::(Fig:Process in Memory)
6 Program occupy fixed place in storage or Process changes its state during execution.
main memory
3.1.2.Process State
Process States
1.In multiprogramming system, many processes are executed by the OS,but at
any instant of time only one process executes on the CPU.other process wait
for their run.
2.The current activity of a process is known as its state.As a process executes it
changes state.The process state is an indicator of the nature of the current
activity in a process.
3.Following fig shows Process state diagram.A state diagram represents the
different states in which a process can be at different times,along with the
tranisitions from one state to another that are possible in the OS.
• Each process may be in one of the following states.
1.New State:
1.A process that has just been created but has not yet been admitted to the
pool of execution processes by the OS.
2.Every new operation which is requested to the system is known as new born
process.
Process State
2.Ready State
1.When a process ready to execute but it is waiting for the CPU
to execute then this is called as ready state.
2.After the completion of the input and outputs the process will be on ready
State means the process will wait for the processor to execute.
3.Running State
1.The process that is currently being executed.
2.when the process is running under the CPU,or when the program is executed
by the CPU,then this is called as Running state.
3.And When a process is running then this will also provide us some output on
the screen.
4.Waiting or Blocked
1.A process that cannot execute until some event occurs or an I/O completion.
2.When a process is waiting for some input and output operations then this is
called as waiting state.
3.And in this state process is not under the execution instead the process is stored
out of memory and when the user will provide the input then this will again be on
ready state.
Process state
5.Terminated State
1.After the completion of the process,the process will be automatically
terminated by the CPU.,so this is called as terminated state of the process.
2.After executing the whole process the processor will also de allocate the
memory which is allocated to the process.so this is called as the terminated
process.
A Process are availble into any one of the state while execution.
State/Activity Description
New Process is being executed.
Process Number
Program Counter
CPU Registers
Memory Allocation
Event information
--The PCB serves as the repository for any information that may vary from process to
Process.
3.2.Process Scheduling
Add a process to the ready queue
Job
completed
3.2.Process Scheduling
1.Many programs at a time on the computer but there is a single CPU . so for
running all the programs concurrently or simultaneously, then we use the
scheduling.
2.Scheduling is that in which each process have some amount of time of
CPU . Scheduling provides time of CPU to the each process.
3.When two or more processes compete for the CPU at the same time then
choice has to be made which process to allocate the CPU next.
4.This procedure of determining the next process to be executed on the CPU is
called as process Scheduling and the module of the OS that makes this
decision is called the scheduler.
5.Processor scheduling is one of the primary function of a multiprogramming
OS . The process of scheduling can be explained with the help of Fig.
6.The process scheduler is the component of the OS that is responsible for
deciding whether the currently running process should continue running and if
not ,which process should run next.
7.The allocation strategy for a job/process to a processor is called process
scheduling.
3.2.1.Scheduling Queues
1.For a uniprocessor system, there will never be more than one running process . If
there are more than one processes , the rest will have to wait until the CPU is free and
can be rescheduled.
2.The process which are ready &waiting to execute ,are kept on a list called the ready
queue.
3.The list is generally a linked list . A ready queue header will contain pointers to the
First and last PCB’s in the list . Each PCB has a pointer field which points to the next
process in the ready queue.
4.There are also other queue in the system . when a process is allocated the CPU, it
executes for a while and eventually quits , is interrupted or waits for the occurrence of a
Particular event , such as the completion of an I/O request.
5.The process therefore may have to wait for the disk . The list of process waiting for a
particular I/O device is called as Device Queue . Each device has its own device queue.
Ready
Queue Head
Registers Registers
Tail
* *
3.2.1.Scheduling Queues
Queue Header PCB7 PCB2
Ready Head
Queue Registers Registers
Tail
Mag
Head
Tape
Unit 0 Tail
Mag
Head
Tape
Unit 1 q PCB3 PCB14 PCB6
Tail
Disk Head
Unit 0
Tail
PCB5
Terminal
Head
Unit 0 Tail
Interactive
Programs Suspended Queue
Medium
Term Scheduler
Types of Schedulers
• Long-Term Scheduler
• It is also called a job scheduler. The long term scheduler determines which jobs are
admitted to the system processing.
• In batch system there are more jobs submitted that can be executed
immediately.These jobs are spooled to mass storage device,where they are kept for
latter execution(ready queue).
• The long term scheduler selects jobs from this job pool and loads into memory for
execution.it is called as job scheduler or admission Scheduler.
• It selects processes from the queue and loads them into memory for execution.
Process loads into the memory for CPU scheduling.
• 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.
• If the degree of multiprogramming is stable, then the average rate of process
creation must be equal to the average departure rate of processes leaving the
system.
• On some systems, the long-term scheduler may not be available or minimal. Time-
sharing operating systems have no long term scheduler.
• When a process changes the state from new to ready, then there is use of long-
term scheduler.
Types of Schedulers
• Medium-Term Scheduler
• On some system,the long term scheduler may be absent or minimal.For example,time
sharing systems such as Unix and Microsoft Windows Systems often have no long term
scheduler but simply put every new process in memory for short term scheduler.
• Some Os such as time sharing systems,may introduce an additional intermediate level of
Scheduling(medium term scheduler).
• It is part of Swapping so it is also known as swapper. Swapping clears the memory of
the processes.
• The degree of multiprogramming is reduced. The switched out processes are handled by
the medium-term scheduler.
Swap In Swap Out
Partially executed Swapped Out
Processes
•
End
Ready Queue CPU
Child
Execution
Child process creation
1. Scheduler which selects the job or The Scheduler which picks up The medium term Scheduler is
processes which are ready to job from pool and loads into that it removes the process from
execute from the ready queue and main memory for execution is main Memory and again reloads
allocate the CPU to one of them is called as Long Term Scheduler. afterwards when required.
called Short Term Scheduler.
4. Speed is very fast. Speed is lessor than short term Medium term scheduler is
scheduler. called whenever required.
5. It deals with CPU. It deals with main memory for It deals with MM for removing
loading process. processes and reloading
whenever required.
7. Minimal in time sharing Absent or minimal in time Time sharing system use
Sharing system medium term scheduler.
Context Switching
Information Placeholder
Fig.A Typical IPC Facility
3.3.1.Introduction To IPC
1.Processes executing concurrently in the operating system might be either independent processes
or co-operating processes.
2.Interprocess communication is a set of programming interfaces that allow a programmer to
co-ordinate activities among different program processes that can run concurrently in the
operating system.
3. This allows a program to handle many user request at the same time.
4. Since even a single user request may result in multiple processes running in the OS on the
user’s behalf,the processes need to communicate with each other .the IPC interfaces is make this
Possible.
5. The interprocess communication is a set of technique for the exchange of data among multiple
Processes. IPC technique divided into method for synchronization ,message passing ,stored
memory etc.
6. A capability supported by some OS that allows one process to communicate with another
process the processes can be running on the same computer or different computer connected
through a network.
7. IPC enables one application to control another application and for several application to share
the same data without interfering with one another.
8. IPC is required in all multiprocessing systems ,but it is not generally supported by single
process operating system such as DOS, OS/2 and Ms Windows etc.
Purpose Of IPC::
1.Data transfer ,sharing data, even tnotification ,Resources sharing and synchronization and
process control .
2.Interprocess communication is one of the most common concepts used in OS and distributed
computing systems. it deals with how multiple process can communicate among each other.
3. Two fundamental models allows inter process communication as explained below :
1.shared memory model :
To processes exchange data or information through sharing region .they can read and write data
from and to this region.
2. Message passing model
In message passing model the data or information is exchanged in the form of messages..
Fig.Communication Model
Process A
Process A M Shared memory
1
M Process B
2
Process B
2 2 1
Kernel M Kernel
P2 address Space
P1 address space
Shared
V
Memory
Process P1
send(j,m) receive(i,m)
i j
Fig : An example Of Direct Message Passing
2.Indirect Communication:
1. With indirect communication the message is sent to and received from mailboxes
or ports .
2.Mailbox where messages can be placed by processes and from which messages can
be removed. Receive Receive
3. Each mailbox has a Unique Identification.Two processes can communicate only if
they share a mailbox. the send and receive primitives are defined as follows:
i)send(A,message):Send a message to mailbox A.
ii)receive(A,message):Receive a message from mailbox A. Mail Box
4. In this scheme a communication link has the following properties:
1. A link is established between a pair of processes only if the both members of the
pair have a shared mailbox.
2. A link may be associated with more than two processes.
3. Between each pair of communicating processes ,there may be number of different
links with each link corresponding to one mailbox. Send
5. Suppose processes P1, P2, P3 all shares mailbox. A process P1 sends to a message A
while P2 and P3 each execute a received from A. A mailbox owned by operating system is
independent and is not attached to any particular process.
6. The operating system that must provide a mechanism that allows a process to do
the following :
1.create new mailbox
2. send and receive message through the mailbox .
3.delete a mailbox
Sychronization
1. Communication between processes takes place by calls to send and receive
primitives .There are different design options for implementing each primitive.
2. Message passing may be blocking or non blocking also known as synchronous and
asynchronous.
3. 1.Blocking Send: The sending process is a blocked until the message is received
by the receiving process or by the mailbox.
2.Non-Blocking send: The sending process sends the message and resumes
operations.
3.Blocking Receives: The receive blocks until a message is available.
4.Non-blocking Receive: The receive retrieves either a valid message or a null.
4. Different combination of send() and receive() are possible. when both the send
and receive are blocking we have a meeting between the sender and the receiver.
3.4.Threads
1. A thread, sometime called a Light Weight process (LWP)is a basic unit of CPU utilization; it
comprises a thread ID , program counter, a register set and a stack .
2.A thread is defined “as a unit of concurrency within a process and had access to the entire code
and data parts of the process”. thus thread of the same process can share their code and data
with one another.
3. It Shares with other threads belonging to the same process its Code section ,data section and
other operating system resources such as open files and signals.
4. Traditional (or heavyweight) process has a single thread of a control. If a process as a multiple
thread i.e.it can do more than one task at a time .Many software packages that run on desktop
PC’S are multithreaded.
5. A word processor may have a thread for displaying graphics ,another thread for reading key
strokes from the user and third thread for performing spelling and grammar checking in the
background etc. Threads play a vital role in Remote Procedure Call(RPC) systems.
6.RPC system RPC as the name implies a communication mechanism that allows a process to call
a procedure on a remote system connected via network the calling process (client) can call the
procedure on the remote host (server) in the same way as it would call the local procedure.
• Multithreaded Programming:
• 1. A Thread is the fundamental unit of CPU utilization. A thread is a program
execution that uses resource of a process.
• 2. A traditional or heavyweight process has a single thread of control comprises a
single thread of a control i.e. it can execute one task at a time and thus is referred
to as a single-threaded process.
• 3. If a process has a multiple threads of control .it can perform more than one task
at a time such a process is known as multithreaded process.
Thread
3 Process It has its own copy of the data segment of the It has direct access to the data segment of its process.
parent process.
4 Communication Processes must use Interprocess Threads can be directly communicate with other threads
Communication to communicate with sibling of its process.
process.
5 Overheads Processes have considerable overhead Threads have almost no overhead.
6 Creation New processes require duplication of the New threads are easily created.
parent process.
7 Control Processes can only exercise control over child Threads can exercise considerable control over threadsof
processes. the same process.
8 Changes Any change in the parent process does not Any change in the main thread may affect the behaviour
affect child processes. of the other threads of the process.
9 Memory Run in separate memory spaces. Run in shared memory spaces.
10 File Description More file descriptors are not shared. It shares file system context.
11 File System There is no sharing of the file system context. It shares file system context.
Kernel Space
CPU
User space
Kernel Space
CPU
• Fig:Kernel Level Space.
• 1. The threads implemented at the kernel level are known as kernel thread are supported
directly by the operating system.
• 2. The kernel performs thread creation, scheduling and Management in Kernel space.because
thread management is a done by the operating system,kernel threads are generally slower to
create and manage than are user thread.
• 3. However since the kernel is managing the threads, if a thread performs a blocking system
call, the kernel can schedule another thread in the application for execution. Also in a
multiprocessor environment ,the kernel can schedule threads on a different processor.
• 4.Most contemporary operating system including Windows NT ,windows 2000,BeOS and
Tru64 UNIX-support kernel threads.
• Advantages Of kernel Level Threads:
• 1. Kernel can simultaneously schedule multiple thread from the same process on multiple processes.
• 2. if one thread in a process is blocked, the kernel can schedule another thread of the same process.
• 3. kernel routine themselves can multithreaded.
• Disadvantages Of Kernel Level Threads:
• 1. The kernel -level thread are slow and inefficient for instance ,threads operationsare hundreds of times
slower than that of user -level thread.
• 2. Transfer of control from one thread to another within the same process requires a mode switch to the
kernel.
1 User level thread are faster to create and Kernel level thread are slower to
manage . create and manage.
3 User level thread can run on any operating kernel level thread are specific to the
system. operating system .
K
•
• Kernel Thread
K K K K
• 1. The one to one model maps each user thread to a kernel thread .
• 2.It provides more concurrency than the many -to -one model by allowing another thread to run when a
thread makes a blocking system call ;it also allows multiple threads to run in parallel on multiprocessors
• 3. Windows NT ,windows 2000 and OS/2 implement the one –to- one model.
• Advantages
1. Multiple Threads can run parallel.
2. less complication in the processing.
• Disadvantages
1. thread creation involves lightweight process creation.
2. every time with user’s thread kernel thread is created .
3.Limited the number of Total thread.
4. kernel thread is an overhead .
5.it reduce the performance of system
3.4.3.2.Many-to-one Model
1.The many- to -one model maps many user threads one kernel thread .Thread management is
done in user space, so it is efficient but the entire process will block if a thread makes a blocking
system call .
2.only one thread can access the kernel at a time. multiple Threads are unable to run in
parallel on multiprocessors.
3.Green threads a thread library available for solaris 2-uses this model.
User Thread
Fig:Many-to-One Model
Kernel Thread
K
Advantages
1. Totally portable.
2. Easy to do with few system dependencies .
3. mainly used in language system portable libraries.
4. Efficient system in terms of performance
Disadvantages
5. cannot take advantage of parallelism
6. one block call blocks all user threads.
3.4.3.3.Many-to-Many Model
User Thread
Kernel Thread
K K K
1. The many- to –many model multiplexes many user level threads to a smaller or equal number of kernel
threads.
2. The number of kernel Threads may be specific to either a particular application or particular machine .
3. this model allows developer to create as many Threads .concurrency is not gained because the kernel can
schedule only one thread at a time.
4. The one to one model allows for Greater concurrency .but the developer has to careful not to create too
many Threads within an application.
5. solaris 2, IRIX, HP-UX and Tru64 UNIX support this model.
• Advantages
• 1.Many Threads can be created as per user’s requirenment.
• 2.2multiple kernel or equal to user that can be created
• Disadvantages
• 1. True concurrency cannot be achieved.
• 2. multiple Threads of kernel is an overhead for operating system.
• 3. performance is less.