0% found this document useful (0 votes)
1 views42 pages

Ch6 Process

The document provides an overview of process management in operating systems, covering concepts such as process states, process control blocks, scheduling, and interprocess communication. It explains the differences between programs and processes, the roles of various schedulers, and the mechanisms for process creation and termination. Additionally, it discusses cooperating processes, synchronization, and client-server communication models.

Uploaded by

sohomkar42
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)
1 views42 pages

Ch6 Process

The document provides an overview of process management in operating systems, covering concepts such as process states, process control blocks, scheduling, and interprocess communication. It explains the differences between programs and processes, the roles of various schedulers, and the mechanisms for process creation and termination. Additionally, it discusses cooperating processes, synchronization, and client-server communication models.

Uploaded by

sohomkar42
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

Prepared by: Lipika Datta

Content
 Process Concept
 Process Scheduling
 Operations on Processes
 Cooperating Processes
 Interprocess Communication
 Communication in Client-Server Systems
Process Concept
 An operating system executes a variety of programs:
 Batch system – jobs
 Time-shared systems – user programs or tasks
 The terms job and process are used almost
interchangeably.
 Process – a program in execution; process execution must
progress in sequential fashion.
 A program is a passive entity such as a file containing a
list of instructions stored on disk.
 A process is an active entity with a program counter
specifying the next instruction.
 A program becomes a process when an executable file is
loaded into memory.
Process Concept
 A process includes:
 Program counter
 Stack: contains temporary data (function parameter,
return address, local variable)
 Data section: contains global variables
 Heap: This memory is dynamically allocated during
process run time.
• More than one processes may be associated with same
program.
• The text section of the different processes are equivalent;
the data, heap and stack sections vary.
Process Concept
 Difference between process and program
Program Process
Program contains a set of Process is an instance of an
instructions designed to executing program.
complete a specific task.
Program is a passive entity Process is a active entity as
as it resides in the it is created during
secondary memory. execution and loaded into
the main memory.
Program exists at a single Process exists for a limited
place and continues to exist span of time as it gets
until it is deleted. terminated after the
completion of task.
Process Concept
 Difference between process and program
Program Process
Program is a static entity. Process is a dynamic entity.
Program does not have any Process has a high resource
resource requirement, it requirement, it needs
only requires memory space resources like CPU,
for storing the instructions. memory address, I/O
during its lifetime.
Program does not have any Process has its own control
control block. block called Process
Control Block.
Process State
As a process executes, it changes state. Each process may be
in one of the following 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
process.
 terminated: The process has finished execution.
At any instant, only one process can be running on
processor. Many processes may be ready or waiting.
Process State Transition Diagram
Process Control Block (PCB)
Each process is represented in the OS by a PCB.
Information associated with each process:
 Process state: State may be new, ready, running,
waiting, halted.
 Program counter: The counter indicated the address
of the next instruction to be executed for this
process.
 CPU registers: They include accumulators, index
registers, stack pointer and general purpose registers
etc.
 CPU scheduling information: This includes process
priority, pointers to scheduling queue and other
scheduling information.
Process Control Block (PCB)
 Memory-management information: This include value
of base and limit registers, the page tables, the
segment tables etc.
 Accounting information: It includes the amount of
CPU and real time used, time limits, job or process
number etc.
 I/O status information: It includes the list of I/O
devices allocated to the process, a list of open files
etc..
PCB serves as a repository for any information that may
vary from process to process.
Process Control Block (PCB)
CPU Switch From Process to Process
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.
Ready queue is stored as linked list. A ready queue
header contains a pointer to the first and final PCBs
in the list. Each PCB includes a pointer field that
points to the next PCB in the ready queue.
Representation of Process Scheduling
Schedulers
 Long-term scheduler (or job scheduler) – selects processes
from the pool of processes in a mass storage device and
loads them in the ready queue in memory for execution.

 Short-term scheduler (or CPU scheduler) – selects among


the processes that are ready to execute and allocates the
CPU to one of them.
Schedulers
Schedulers
 Compare between Long term and short term scheduler.
Long term scheduler Short term scheduler
Select a process from job Select a process from ready
pool queue
Known as Job Scheduler Known as CPU Scheduler

Regulates degree of Does not regulate degree of


multiprogramming multiprogramming
Speed is less than Short term Speed is more than Long
scheduler term scheduler

changes the process state changes the process state


from New to Ready. from Ready to Running.
It select a good process, mix It select a new process for a
of I/O bound and CPU CPU quite frequently.
bound.
Addition of Medium Term
Scheduling
Schedulers (Cont.)
 Short-term scheduler is invoked very frequently
(milliseconds)  (must be fast).
 Long-term scheduler is invoked very infrequently
(seconds, minutes)  (may be slow).
 The long-term scheduler controls the degree of
multiprogramming.
 Processes can be described as either:
 I/O-bound process – spends more time doing I/O
than computations, many short CPU bursts.
 CPU-bound process – spends more time doing
computations; few very long CPU bursts.
Context Switch
 Interrupts cause the OS to change the CPU from its
current task and to run kernel routine.
 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.
 The context is represented in the PCB of the process: It
includes the value of the CPU registers, the process
state and memory management information etc.
 It is called the state save of the current state of the
CPU.
 Time dependent on hardware support.
Context Switch
 What is context switching?
 Switching the CPU to another process requires
performing a state save of the current process and a
state restore of a different process. This task is known
as context switch.
 When context switch occurs, the kernel saves the
context of the old process in its PCB and loads the
saved context of the new process scheduled to run.
 Explain: “Context-switch time is pure overhead.”
Process Creation
 A process may create several new processes via a create-
process system call during the course of execution.
 The creating process is called parent process and the new
processes are called the children of that process.
 Parent process create children processes, which, in turn
create other processes, forming a tree of processes.
 Most OS s identify a process by an unique integer number
which is called the PID of the process.
 Resource sharing
 Parent and children share all resources.
 Children share subset of parent’s resources.
 Parent and child share no resources.
Process Creation (Cont.)
 Execution
 Parent and children execute concurrently.
 Parent waits until children terminate.

 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 Creation (Cont.)
Process Creation (Cont.)
Process Termination
 Process executes last statement and asks the operating
system to decide it (exit).
 Output data from child to parent (via wait).
 Process’ resources are deallocated by operating system.
 Parent may terminate execution of children processes
(abort).
 Child has exceeded allocated resources.
 Task assigned to child is no longer required.
 Parent is exiting.
 Operating system does not allow child to continue if
its parent terminates.
 Cascading termination.
Cooperating Processes
 Independent process cannot affect or be affected by the
execution of another process. Any process that does not
share data with any other process is independent process.
 Cooperating process can affect or be affected by the
execution of another process. Any process that shares data
with any other process is cooperating process.
 Advantages of process cooperation
 Information sharing : Several users may be interested in
same piece of information, so an environment must be
provided to allow concurrent access to such
information.
Cooperating Processes ( Contd..)
 Computation speed-up: If a task is to run faster, it must
be broken into sub tasks each of which could be
executing in parallel in multiprocessor environment
 Modularity: A system can be constructed in modular
fashion, dividing the system into seperate processes or
threads.
 Convenience: An individual user may work on many
tasks at the same time.
Two fundamental methods for interprocess communication:
1. Shared memory
2. Message passing
Producer-Consumer Problem
 Paradigm for cooperating processes, producer process
produces information that is consumed by a consumer
process.
 unbounded-buffer places no practical limit on the size
of the buffer.
 bounded-buffer assumes that there is a fixed buffer size.
Bounded-Buffer – Shared-Memory
Solution
 Shared data
#define BUFFER_SIZE 10
Typedef struct {
...
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
 Solution is correct, but can only use BUFFER_SIZE-1
elements
Bounded-Buffer – Producer Process
item nextProduced;

while (1) {
while (((in + 1) % BUFFER_SIZE) == out)
; /* do nothing */
buffer[in] = nextProduced;
in = (in + 1) % BUFFER_SIZE;
}
Bounded-Buffer – Consumer
Process
item nextConsumed;

while (1) {
while (in == out)
; /* do nothing */
nextConsumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
}
Interprocess Communication (IPC)
 Mechanism for processes to communicate and to synchronize
their actions.
 Message system – processes communicate with each other
without shared variables.
 IPC facility provides two operations:
 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
 Implementation of communication link
 physical (e.g., shared memory, hardware bus)
 logical (e.g., logical properties)
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.
 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.
Indirect Communication
 Operations
 create a new mailbox
 send and receive messages through mailbox
 destroy a mailbox
 Primitives are defined as:
send(A, message) – send a message to mailbox A
receive(A, message) – receive a message from mailbox A
Indirect Communication
 Mailbox sharing
 P1, P2, and P3 share mailbox A.
 P1, sends; P2 and P3 receive.
 Who gets the message?
 Solutions
 Allow a link to be associated with at most two
processes.
 Allow only one process at a time to execute a receive
operation.
 Allow the system to select arbitrarily the receiver.
Sender is notified who the receiver was.
Synchronization
 Message passing may be either blocking or non-blocking.
 Blocking is considered synchronous
 Non-blocking is considered asynchronous
 send and receive primitives may be either blocking or
non-blocking.
 Blocking send: The sending process is blocked until the
message is received by the receiving process or by the
mailbox.
 Non blocking send: The sending process sends the
message and resumes operation.
 Blocking receive: The receiver is blocked until a message
is available.
 Non blocking receive: The receiver retrieves either a valid
message or a null.
Synchronization
Synchronization
Buffering
 Queue of messages attached to the link; implemented in
one of three ways.
1. Zero capacity – 0 messages
Sender must wait for receiver.
2. Bounded capacity – finite length of n messages
Sender must wait if link full.
3. Unbounded capacity – infinite length
Sender never waits.
Client Server communication
 Socket
 Remote Procedure Call

You might also like