Operating Systems
Processes (a)
Operating Systems 1
Roadmap
• Process Concept
• Process Elements
• Process Control Block ( PCB)
• Process States
• Switching between processes
• Process Scheduling
• Types of Queues ( Job, ready, device)
• Schedulers ( Short, Long, Medium)
• Operations on Processes (Process Creation and Termination)
• Interprocess Communication
Operating Systems 2
Process
Definition
Program vs. Process
• A program is a passive entity such as the file that
contains the list of instructions stored on a disk always
referred to as an executable file.
• A program becomes a process when an executable file is
loaded into the memory and then becomes an active
entity or an activity.
• The fundamental task of any operating system is
the
process management.
Operating Systems 3
Operating Systems 4
Feature Program Process
Static set of Dynamic instance of a
Definition instructions program in execution
State Passive Active
Stored on secondary Resides in main
Location storage (disk) memory (RAM)
Allocated CPU time,
No dedicated memory, and other
Resources resources resources
Python script, C++ Web browser window,
Examples program music player process
Operating Systems 5
Relation Between Program
And Process
• Program is passive entity, process is active
– Program: Static code + static data
– Process: Dynamic instantiation of code + data + more
• Program becomes process when executable file loaded
into memory
• Few processes are built-in and hence they do not
originate from any programs as system services, kernel
processes.
• No 1 to 1 mapping between program and process
– One program may run many processes
Separate execution sequences
– Multiple users may execute the same program
6
Text section is equivalent
Resource
Allocation
• OS must allocate resources to processes, enable sharing
of information, protect resources, and enable the
synchronization among processes.
Operating Systems 7
Process
Elements
• Process is loaded in Main Memory and divided
into various parts.
Stack: Stores temporary data like parameters,
return values, local variables.
Heap: Dynamically allocated memory to process
during its run-time.
Data: Global & Static variables
Text: Program counters for next instructions, the
program code. This is typically read-only and
might be shared by a number of processes.
Operating Systems 8
Process Control
Each process state is represented in the operating by a Process
ControlBlock
Block (PCB).(PCB)
For better control of processes , Operating system needs to check
their current behavior.
• OS keeps all the data it needs about a process in the process
control block (PCB)
– Process state information
– Program counter
– CPU registers
– CPU scheduling information
– Memory-management information
– Accounting information
– I/O status information
Operating Systems 9
Process Control Block
(PCB)
• Process Control Block (PCB)
Processor state Information
Process state – running, waiting, etc
Program counter
location of instruction to next execute
CPU registers
contents of all process-centric registers
Operating Systems 10
Process Control Block
(PCB)
• Process Control Block (PCB)
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
Operating Systems 11
Process Control Block
(PCB)
• Process Control Block (PCB)
Process identification information
Process identifier: numeric identifiers
represent the unique process identifier
User identifier: the user who is responsible for the job).
Identifier of the parent process that created this process.
Operating Systems 12
Process Control Block-
Summary
• Distinction between processes
• Knowledge on processes
ready to execute
• Discriminate between
processes
• Know the next instruction to
execute
• Find the program and data
stored in memory
• Keep information about
registers
• Keep track about resources, e.g.,
I/O devices
• Collect information on
utilization of the system
13
Why PCBs?
• By maintaining a PCB for each process, the operating
system can effectively:
• Manage the execution of multiple processes
• Allocate system resources
• Schedule CPU time
• Handle process synchronization and communication.
• The PCB serves as a crucial data structure that allows the
operating system to maintain and control the state of each
process, ensuring efficient and orderly execution of tasks
within the system.
Operating Systems 14
CPU Switch From Process to Process
Process
Dispatcher/Scheduler
• OS program that decides which
process to run next from set of
available processes.
• Uses Process Control Block (PCB)
information
– Decision what is the next
process to execute
16
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
• Processes migrate among the various queues
Operating Systems 17
Process States
• As a process executes, it changes 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 processor
Terminated: The process has finished execution
Operating Systems 18
Process States
• Diagram of Primary Process State
Secondary/Additional Process States: Suspended
Operating Systems 19
Schedulers
Long term scheduler – Job scheduler
Short term scheduler – CPU scheduler
Medium term scheduler - Swapper/ swap space
December 14, 2024
Long Term Scheduler
Long-term scheduler (or job scheduler) – selects
processes from the job pool to be brought into the ready
queue.
Long-term scheduler is invoked very infrequently (seconds,
minutes) (may be slow).
The long-term scheduler controls the degree of
multiprogramming.
December 14, 2024
Short Term Scheduler
Short-term scheduler (or CPU scheduler) – selects which
process should be executed next and allocates it the CPU
through the dispatcher.
Short-term scheduler is invoked very frequently (milliseconds)
(must be fast).
Invoked when following events occur
CPU slice of the current process finishes
Current process needs to wait for an event
Clock interrupt
I/O interrupt
System call
Signal
December 14, 2024
Medium Term Scheduler
Also known as swapper
Selects an in-memory process and swaps it out to the
disk temporarily
Swapping decision is based on several factors
Arrival of a higher priority process but no memory available
Poor mix of jobs [I/O bound, CPU bound]
Memory request of a process cannot be met t
December 14, 2024
Difference between Schedulers
Operating Systems 24
Addition of Medium Term
Scheduling
December 14, 2024
CPU and I/O Bound Processes
Processes can be:
I/O-bound process – spends more time doing I/O than computations,
many short CPU bursts.
I/O Burst CPU Burst I/O Burst CPU Burst
CPU-bound process – spends more time doing computations;
few very long CPU bursts.
CPU Burst I/O CPU Burst I/O
December 14, 2024
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
• The more complex the OS and the PCB -> longer the context switch
• Time dependent on hardware support
• Some hardware provides multiple sets of registers per CPU -> multiple
contexts loaded at once