Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
23 views45 pages

Dms - 6405a8a51702cOS Module II Part I

Uploaded by

Spandan Sahu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views45 pages

Dms - 6405a8a51702cOS Module II Part I

Uploaded by

Spandan Sahu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

Module-II (Part-I):

Process Management

by:
Dr. Soumya Priyadarsini Panda
Assistant Professor
Dept. of CSE
Silicon Institute of Technology, Bhubaneswar
Contents

 Process Concept

 Process Scheduling

 Operations on Processes

 Inter Process Communication (IPC)


Process Concept
 A process is a program in execution.

 An operating system executes a variety of programs:


 Batch system – jobs
 Time-shared systems – user programs or tasks

 Process execution must progress in sequential manner

 A process includes:
 program counter
 stack
 data section
The Process
 A process has multiple parts

 The program code, also called text section

 Current activity including program counter, processor registers

 Stack containing temporary data


 Function parameters, return addresses, local variables

 Data section containing global variables

 Heap containing memory dynamically allocated during run time


Structure of a Process in Memory
Difference between Program and
Process
 Program is passive entity, process is active .

 Program becomes process when executable file loaded into memory.

 Execution of program started via GUI mouse clicks, command line


entry of its name, etc

 One program can be several processes

 Consider multiple users executing the same program


 Each of these is a separate process
Process States

 A process is a program in execution.

 When a process executes it changes its state.


Process States
Process States
New:
 The process is being created

Running:
 Instructions are being executed

Waiting:
 The process is waiting for some event to occur

Ready
 The process is waiting to be assigned to a processor

Terminated:
 The process has finished execution
Process Control Block (PCB)

 Each Process is represented in the OS by a Process Control


Block(PCB).

 Also called as task control block.

 It contains various information associated with a specific process


PCB Cont…
PCB Cont…
Information associated with each process:
Process state:
 The state may be new, ready, running, waiting, etc

Program counter:
 Indicates the address of the next instruction to be executed for this
process.

CPU registers:
 Contents of all process-centric registers
PCB Cont…
CPU scheduling information:
 priorities, scheduling queue pointers

Memory-management information:
 memory allocated to the process

Accounting information:
 CPU used, clock time elapsed since start, time limits

I/O status information:


 I/O devices allocated to process, list of open files
CPU Switch from Process to Process
Process Scheduling
 Process scheduling refers to the mechanism that provides the order
in which the process is to be executed.

 Maximize CPU use, quickly switch processes onto CPU for time sharing

 Process scheduler selects among available processes for next


execution on CPU

 Maintains scheduling queues of processes: Job queue, Ready


queue, Device queue

 Processes migrate among the various queues


Scheduling Queues
Job Queue:
 As processes enters to the System, they are stored into a job queue
which consist of all processes in the system

Ready Queue:
 The processes that are residing in main memory and are ready and
waiting to execute in CPU are kept in the ready queue

Device Queue:
 The list of processes waiting for a particular I/O device are kept in
device queue.
Representation of Process Scheduling

 Queueing diagram represents queues, resources, flows


Schedulers
 A process moves in between various scheduling queues through out its
lifetime.

 The selection process is carried out by the appropriate schedulers.

Types of Schedulers:
 Long term schedulers (Job schedulers)
 Short term schedulers (CPU schedulers)
Long Term Schedulers (Job Schedulers)

 Selects which processes should be brought into the ready queue.

 Long-term scheduler is invoked less frequently (seconds, minutes)

 The long-term scheduler controls the degree of multiprogramming.

 The long-term scheduler must make a careful selection of processes


Cont…
 Processes can be described as:

I/O-bound process:
 spends more time doing I/O than computations
 short CPU bursts

CPU-bound process
 spends more time doing computations
 very long CPU bursts

 Long-term scheduler must select a mix of I/O-bound and CPU-


bound processes.
Short Term Schedulers (CPU Schedulers)

 Selects which process should be executed next and allocates CPU

 Sometimes the only scheduler in a system

 Short-term scheduler is invoked frequently (in some milliseconds)


Long Term Vs. Short-term Schedulers
Addition of Medium Term Schedulers
 Some operating systems, such as time sharing systems, may introduced
an additional intermediate level of scheduling-
 medium term schedulers

 The idea behind the medium term scheduler is that-


 Sometimes it can be advantageous to swapped out the process from
memory to reduce the degree of multi programming.
 The swapped out process can be swapped in later to finish its
execution.

 This scheme is called swapping and is performed by the medium term


scheduler.
Cont…
Difference between Schedulers
Long-Term Short-Term Medium-Term
Long term is also known as Short term is also known as Medium-term is also called
a job scheduler CPU scheduler swapping scheduler.

It is either absent or minimal It is insignificant in the This scheduler is an element


in a time-sharing system. time-sharing order. of Time-sharing systems.

Speed is the fastest


Speed is less compared to
compared to the short-term It offers medium speed.
the short term scheduler.
and medium-term scheduler.
Allow you to select It only selects processes that
It helps you to send process
processes from the loads and is in a ready state of the
back to memory.
pool back into the memory execution.
Reduce the level of
Offers full control Offers less control
multiprogramming.
Context Switching

 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


Cont…

 Context-switch time is overhead; the system does no useful work


while switching

 The more complex the OS and the PCB -> longer the context switch

 Time dependent on hardware support


Operations on Process

 Processes in most systems can execute concurrently, and they may


be created and deleted dynamically

 Process Creation

 Process Termination
Process Creation
 Parent process create children processes, which, in turn may create
other processes, forming a tree of processes.
 A process is 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
Cont…
Address Space:
 Child duplicate of parent
 Child has a program loaded into it

UNIX examples
 fork() system call creates new process
 exec() system call used after a fork() to replace the process
memory space with a new program
Process Termination

 A process terminates when it finishes executing its final statement


and asks the operating system to delete it by using the exit() system
call.

 All the resources of the process: physical and virtual memory, open
files, and I/O buffers, etc are deallocated by the operating system.
Cont…
 Parent may terminate the execution of children processes using the
abort() system call-

 Reasons:
 Child has exceeded allocated resources
 Task assigned to child is no longer required
 The parent is exiting and the operating systems does not allow a
child to continue if its parent terminates

 A parent process may wait for the termination of a child process by


using the wait() system call.
Cont…
 Some operating systems do not allow child to exists if its parent has
terminated.

 If a process terminates (normally or abnormally), then all its children


must also be terminated. This phenomenon is referred to as cascading
termination.

 Process that has terminated, but whose parent has not yet called
wait(), is known as a zombie process.

 If a parent did not invoke wait() and terminated, leaving its child
processes, the child process is known as orphan process.
Inter Process Communication (IPC)

 Processes executing concurrently in the operating system may be:

 Independent Processes

 Cooperating processes
Cont…
Independent Process:
 If the process cannot affect or be affected by the other processes
executing in the system.
 Any process that does not share data with any other process is
independent.

Cooperating process:
 If the process can affect or be affected by the other processes executing
in the system.
 Any process that shares data with other processes is a cooperating
process
Cont…
Reasons for process cooperation:

 Information sharing

 Computation speedup

 Modularity

 Convenience
Cont…
 Cooperating processes need Inter Process Communication (IPC)

Models of IPC:

 Shared memory

 Message passing
Shared Memory

 In the shared-memory model, a region of memory is shared by


cooperating processes.

 Processes can exchange information by reading and writing data to


the shared region.

 Shared memory can be faster than message passing, since message-


passing systems are typically implemented using system calls.
Message Passing Vs. Shared Memory

Message passing Shared Memory


Message Passing

 In the message-passing model, communication takes place by means


of messages exchanged between the cooperating processes

 Message passing is useful for exchanging smaller amounts of data,


because no conflicts need be avoided.

 Message passing is also easier to implement in a distributed system


than shared memory
Cont…
 IPC facility provides two operations for message passing:
 send(message) – message size fixed or variable
 receive(message)

 If P and Q wish to communicate, they need to:


 establish a communication link between them
 exchange messages via send/receive

 Major issues is to provide mechanism that will allow the user


processes to synchronize their actions when they access shared
memory.
Direct Communication
 Processes must name each other explicitly:
 send (P, message) – send a message to process P
 receive(Q, message) – receive a message from process Q

 Properties of communication link


 Links are established automatically
 A link is associated with exactly one pair of communicating
processes
 Between each pair there exists exactly one link
 The link may be unidirectional, but is usually bi-directional
Indirect Communication
 Messages are directed and received from mailboxes (also referred to as
ports)
 Each mailbox has a unique id
 Processes can communicate only if they share a mailbox

 Properties of communication link


 Link established only if processes share a common mailbox
 A link may be associated with many processes
 Each pair of processes may share several communication links
 Link may be unidirectional or bi-directional
Synchronization
 Message passing may be either blocking or non-blocking

 Blocking is considered synchronous


 Blocking send has the sender block until the message is received
 Blocking receive has the receiver block until a message is
available

 Non-blocking is considered asynchronous


 Non-blocking send has the sender send the message and continue
 Non-blocking receive has the receiver receive a valid message or
null
Buffering
 Messages exchanged by communicating processes reside in a
temporary queue implemented in three ways:

Zero capacity:
 No messages are queued on a link.
 Sender must wait for receiver

Bounded capacity:
 Finite length of n messages
 Sender must wait if link full

Unbounded capacity:
 Infinite length
 Sender never waits

You might also like