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

ch02-Process Management

Chapter 2 discusses process management in operating systems, covering concepts such as process states, process control blocks, and scheduling. It explains the roles of different types of schedulers and the operations involved in process creation and termination. Additionally, it highlights interprocess communication methods, including message passing and shared memory for cooperating processes.

Uploaded by

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

ch02-Process Management

Chapter 2 discusses process management in operating systems, covering concepts such as process states, process control blocks, and scheduling. It explains the roles of different types of schedulers and the operations involved in process creation and termination. Additionally, it highlights interprocess communication methods, including message passing and shared memory for cooperating processes.

Uploaded by

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

Chapter 2:

Processes Management
Chapter 2: Processes Management
• Process Concept
• Process Scheduling
• Operations on Processes
• Interprocess Communication
Process Concept
• An operating system executes a variety of programs:
– Batch system – jobs
– Time-shared systems – user programs or tasks
• Textbook uses the terms job and process almost
interchangeably
• Process – a program in execution; process execution
must progress in sequential fashion
• A process includes:
– program counter : it includes current activity
– Stack : which contains temporary data
– data section : contains global variables.
Process in Memory
Process State
• As a process executes, it changes state.
• the state of a process is defined by the current
activity of that process.
– 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
Diagram of Process State
Process Control Block (PCB)
• Each process is represented in the operating system
by a process control block (PCB) also called a task
control block.
Information associated with each process
• Process state
• Program counter
• CPU registers
• CPU scheduling information
• Memory-management information
• Accounting information
• I/O status information
Process Control Block (PCB)
CPU Switch From Process to Process
Process Scheduling
• The process scheduling is the activity of the
process manager that handles the removal of the
running process from the CPU and the selection of
another process on the basis of a particular
strategy.
• Process scheduling is an essential part of a
Multiprogramming operating system.
• Such operating systems allow more than one
process to be loaded into the executable memory
at a time and loaded process shares the CPU using
time multiplexing.
Process Scheduling Queues
• Scheduling queues refers to queues of processes or
devices.
• 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
• Processes migrate among the various queues
Process Scheduling Queues
This figure shows the queuing diagram of process
scheduling.
• Queue is represented by rectangular box.
• The circles represent the resources that serve the
queues.
• The arrows indicate the process flow in the system.
Representation of Process Scheduling
Ready Queue And Various I/O Device Queues
Schedulers
• Schedulers are special system software which
handles process scheduling in various ways.
• Their main task is to select the jobs to be
submitted into the system and to decide which
process to run.
• Schedulers are of three types
Schedulers
• Long-term scheduler (or job scheduler) – selects
which processes should be brought into the ready
queue
• Short-term scheduler (or CPU scheduler) – selects
which process should be executed next and
allocates CPU
• Medium-term scheduler – it is the part of
Swapping. It removes the processes from the
memory and reduces the degree of
multiprogramming. The medium term scheduler is
in-charge of handling the swapped out-processes.
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
Comparison between Scheduler
S.N. Long Term Scheduler Short Term Scheduler Medium Term Scheduler

1 It is a job scheduler It is a CPU scheduler It is a process swapping


scheduler.
2 Speed is lesser than short Speed is fastest among Speed is in between
term scheduler other two both short and long
term scheduler.
3 It controls the degree of It provides lesser control It reduces the degree of
multiprogramming over degree of multiprogramming.
multiprogramming
4 It is almost absent or It is also minimal in time It is a part of Time
minimal in time sharing sharing system sharing systems.
system
5 It selects processes from It selects those It can re-introduce the
pool and loads them into processes which are process into memory
memory for execution ready to execute and execution can be
continued.
CPU Scheduling
• CPU Scheduling is the process of determining
which process should be executed by the CPU
at any given time.
• The goal of CPU scheduling is to maximize the
utilization of CPU and ensure that all
processes are given a fair share of the CPU
time.
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
• Time dependent on hardware support
Dispatcher
• The dispatcher is the module that gives control to
the CPU to the process selected by the short term
scheduler.
• The function involves:-
• switching context
• Switching to user model
• Jumping to the proper location in the user program
to restart that program.
Operations on a Process:
Process Creation
• Process creation is a task of creating a new processes.
• Parent process create children processes, which, in turn
create other processes, forming a tree of processes
• Generally, process identified and managed via a unique
process identifier (pid) which is an integer.
• 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
Process Creation (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 Creation
Process Termination
• Process termination is the operation of terminating or
ending the execution of a process.
• Process executes last statement and asks the operating
system to delete it (exit)
– Output data from child to parent (via wait)
– Process’ resources are deallocated by operating
system
Process Termination(Cont)
• Parent may terminate execution of children processes
(abort)
– Child has exceeded allocated resources
– Task assigned to child is no longer required
– If parent is exiting
• Some operating system do not allow child to
continue if its parent terminates
– All children terminated - cascading termination
Cooperating Processes
• Independent process cannot affect or be affected by
the execution of another process.
• Cooperating process can affect or be affected by the
execution of another process
• Advantages of process cooperation
– Information sharing :- concurrent access
– Computation speed-up:- execute in parallel
– Modularity:- divide task into subtasks or threads
– Convenience:- work on many tasks at the same
time
Interprocess Communication
• Processes within a system may be independent or
cooperating
• Cooperating process can affect or be affected by other
processes, including sharing data
• Reasons for cooperating processes:
– Information sharing
– Computation speedup
– Modularity
– Convenience
• Cooperating processes need interprocess communication (IPC)
• Two models of IPC
– Shared memory
– Message passing
Communications Models

a) Message passing b) Shared memory


Message Passing
• Mechanism for processes to communicate and to
synchronize their actions
• Message system – processes communicate with each
other without resorting to 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
Shared memory system
• It is an Inter Process Communication(IPC) method
that allows multiple processes to share a common
region of memory for data exchange.
• Processes can then exchange information by reading
and writing data to shared region.
• The processes are responsible for ensuring that they
are not writing to the same location simultaneously .

You might also like