0% found this document useful (0 votes)
24 views

Unit 2

Uploaded by

Lalitha
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Unit 2

Uploaded by

Lalitha
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 54

UNIT II

Process Management
Learning Objectives
• Process Concept
• States of a process
• Process Scheduling
• Context switching
• Creation of a Process
• Termination of a process
Learning Objectives (Conti..)

• Cooperating Processes
• Inter-process Communication
• Scheduling criterion
• Basics of scheduling algorithms
• Scheduling algorithms
• Multiprocessor and real-time scheduling
Process Concept
• Process – a program in execution.
• Process execution must progress in
sequential fashion.
• A process includes:
– program counter
– Text section
– Stack section
– data section
States of a Process
• As a process executes, it changes its state
– 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.
State transitions of a process
Process Control Block
• The operating system maintains information
related to a process in a process control
block (PCB).
• This is also called as Task control block
Information in a PCB
• Process state
• Program counter
• CPU registers
• CPU scheduling information
• Memory-management information
• Accounting information
• I/O status information
Process Control Block
Process Scheduling
• Multiprogramming - more than one process
is in running state
• CPU is allocated in a time shared manner
• To schedule various processes - require a
set of queues.
• The processes are sent in to various queues
depending on the state of the 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.
Ready Queue And Various I/O
Device Queues
Representation of Process
Scheduling
Schedulers
• Long-term scheduler
– job scheduler
– selects which processes should be brought into
the ready queue.
• Short-term scheduler
– CPU scheduler
– selects which process should be executed next
and allocates CPU.
Addition of Medium Term
Scheduling
Types of Schedulers
• 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.
Types of Processes
• 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
• Save the state of the old process and load
the state for the new process.
• The context means the values of CPU
registers, process state and memory
management information.
• The speed of the context switch is also
depending on the hardware support
Operations on Processes
• Process Creation:
– Parent process create children processes, which, in turn
create other processes, forming a tree of processes.
– In UNIX fork system call creates new process
• Process Termination
Process Creation (Conti…)

• Resource sharing
– Parent and children share all resources.
– Children share subset of parent’s resources.
– Parent and child share no resources.
• Execution
– Parent and children execute concurrently.
– Parent waits until children terminate.
• Address space
– Child duplicate of parent.
– Child has a program loaded into it.
Process Termination
• Process executes last statement and asks the
operating system to decide it (exit).
– Output data from child to parent (using wait).
– Process’ resources are de-allocated by
operating system.
• A process can terminate another process
using abort system call.
Process Termination (Conti…)

• Parent may terminate execution of children


processes for following reasons:
– Child has exceeded allocated resources.
– Task assigned to child is no longer needed to be
executed.
– When parent process is exiting. Operating system does
not allow child to continue if its parent terminates.
– Terminating all processes that are belonging to the
process is called as Cascading termination.
Cooperating Processes
• Independent process cannot affect or be
affected by the execution of another process
• Independent processes do not share the data
with any other process
• Cooperating process can affect or be
affected by the execution of another process
Advantages of process
cooperation
• Information sharing
• Computation speed-up
• Modularity
• Convenience
Cooperating Processes – A Case
study
• Producer-Consumer Problem
– 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.
Interprocess Communication
(IPC)
• For processes to communicate and to
synchronize their actions
• very popular in a distributed environment
• Processes communicate with each other
without resorting to shared variables is
called as Message-passing system.
IPC (Conti…)

• 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)
Establishing a logical connection
• Naming the process (referring of a
process)
• Synchronization
• Buffering
• Message size
Naming the process

• There are two ways


– Direct communication
– Indirect communication.
Direct communication
• Processes must name each other explicitly:
– send (A, message) – send a message to process A
– receive(B, message) – receive a message from process B
• 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 sent to a mailbox by the sender and
receiver receives them from mailboxes (also referred
to as ports).
o Each mailbox has a unique identification number.
o Communication among the processes is via different
mailboxes.
o Processes can communicate only if they share a mailbox.
o operations on the mailbox.
o create a new mailbox
o send and receive messages through mailbox
o destroy a mailbox
Indirect Communication
  The following primitives are provided by
the IPC to transfer data using Indirect
communication.
– send(A, message) – send a message to mailbox
A
– receive(A, message) – receive a message from
mailbox A
Indirect Communication (Conti…)

• Properties of communication link


o A link is established only if processes share a
common mailbox.
o A link may be associated with many processes.
o Each pair of processes may share several
communication links.
Synchronization
• Message passing may be either blocking or non-
blocking.
• Blocking is considered synchronous
• Non-blocking is considered asynchronous
• Blocking send
• Non-blocking send
• Blocking Receive
• Non-blocking receive
Buffering
• Queue of messages attached to the link
• Implemented in one of three ways.
1.Zero capacity – 0 messages
Sender must wait for receiver (rendezvous).
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
• Sockets
• Remote Procedure Calls
• Remote Method Invocation (Java)
Sockets
Sockets
• A socket is defined as an endpoint for
communication.
• Concatenation of IP address and port
• The socket 161.144.19.8:1234 refers to port
1234 on host 161.144.19.8
• Communication consists between a pair of
sockets.
Remote Procedure Calls
• Remote procedure call (RPC) abstracts procedure
calls between processes on networked systems.
• Stubs – client-side proxy for the actual procedure
on the server.
• The client-side stub locates the server and
marshals the parameters.
• The server-side stub receives this message,
unpacks the marshaled parameters, and performs
the procedure on the server.
Remote Method Invocation
• Remote Method Invocation (RMI) is a Java
mechanism similar to RPCs.

• RMI allows a Java program on one machine


to invoke a method on a remote object.
CPU Scheduling
• Maximum CPU utilization obtained with
multiprogramming
• CPU–I/O Burst Cycle – Process execution
consists of a cycle of CPU execution and
I/O wait.
• CPU burst distribution
Alternating Sequence of CPU And
I/O Bursts
CPU Scheduler
• Selects from among the processes in memory that are
ready to execute, and allocates the CPU to one of them.
• CPU scheduling decisions may take place when a
process:
1. Switches from running to waiting state.
2. Switches from running to ready state.
3. Switches from waiting to ready.
4. Terminates.
• Scheduling under 1 and 4 is non-preemptive.
• All other scheduling is preemptive.
Dispatcher
• Dispatcher module gives control of the CPU to the
process selected by the short-term scheduler; this
involves:
– switching context
– switching to user mode
– jumping to the proper location in the user program to
restart that program
• Dispatch latency – time it takes for the dispatcher
to stop one process and start another running.
Optimizing Criteria
• Maximize Throughput
• Minimize Turnaround Time
• Minimize Response Time
• Maximize Efficiency
• Fairness
• Minimize Waiting Time
First-Come, First-Served (FCFS)
Scheduling
Process Burst Time
P1 24
P2 3
P3 3
• Suppose that the processes arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:

P1 P2 P3
• Waiting time for P1 = 0; P2 = 24; P3 = 27
0
• Average waiting time: (0 + 24 24
+ 27)/327
= 17 30
FCFS Scheduling (Cont.)

Suppose that the processes arrive in the order


P2 , P3 , P1 .
• The Gantt chart for the schedule is:

P2 P3 P1

0 3 6 30
• Waiting time for P1 = 6; P2 = 0; P3 = 3
• Average waiting time: (6 + 0 + 3)/3 = 3
• Much better than previous case.
• Convoy effect short process behind long process
Shortest-Job-First (SJR)
Scheduling
• Associate with each process the length of its next CPU
burst. Use these lengths to schedule the process with
the shortest time.
• Two schemes:
– nonpreemptive – once CPU given to the process it cannot be
preempted until completes its CPU burst.
– preemptive – if a new process arrives with CPU burst length
less than remaining time of current executing process,
preempt. This scheme is know as the
Shortest-Remaining-Time-First (SRTF).
• SJF is optimal – gives minimum average waiting time
for a given set of processes.
Priority Scheduling
• A priority number (integer) is associated
with each process
• The CPU is allocated to the process with the
highest priority (smallest integer  highest
priority).
– Preemptive
– nonpreemptive
Priority Scheduling (Conti…)

• SJF is a priority scheduling where priority


is the predicted next CPU burst time.
• Problem  Starvation – low priority
processes may never execute.
• Solution  Aging – as time progresses
increase the priority of the process.
Round Robin (RR)
• Each process gets a small unit of CPU time (time
quantum), usually 10-100 milliseconds. After this
time has elapsed, the process is preempted and
added to the end of the ready queue.
• If there are n processes in the ready queue and the
time quantum is q, then each process gets 1/n of
the CPU time in chunks of at most q time units at
once. No process waits more than (n-1)q time
units.
Performance of Round Robin

• q large  FIFO
• q small  q must be large with respect to
context switch, otherwise overhead is too
high
Example of RR
Time Quantum = 20
Process Burst Time
P1 53
P2 17
P3 68
P4 24
• The Gantt chart is:
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3

0 20 37 57 77 97 117 121 134 154 162


Typically, higher average turnaround than SJF, but better
response.
Multiple-Processor Scheduling
• Multiple CPUs are available.
• CPU scheduling more complex
• Homogeneous processors within a
multiprocessor.
• Load sharing
• Asymmetric multiprocessing – only one
processor accesses the system data structures,
alleviating the need for data sharing.
Real-Time Scheduling
• Hard real-time systems – required to
complete a critical task within a guaranteed
amount of time.
• Soft real-time computing – requires that
critical processes receive priority over less
fortunate ones.

You might also like