Page 1 of 12
UNIT - II
Processes: Process Concept, Process scheduling, Operations on processes, Inter-
process communication.
Process Concept
Definition of Process
• A process is a program in execution.
• It represents an active entity, unlike a program which is a passive set of instructions
stored on disk.
Program vs Process
Program Process
Passive set of instructions Active execution of instructions
Stored on disk Loaded into memory
No resources allocated Resources allocated (CPU, memory, files)
Static Dynamic
Process States
A process changes states based on CPU availability and I/O needs.
Main states:
• New – Process is created
• Ready – Waiting for CPU
• Running – Executing instructions
• Waiting/Blocked – Waiting for an event (I/O, signal)
• Terminated – Execution completed
Process State Diagram
Page 2 of 12
Process Control Block (PCB)
• A PCB stores all information needed to manage a process.
• The operating system uses the PCB during context switching.
PCB Contains:
• Process ID (PID)
• Process state
• Program counter
• CPU registers
• CPU scheduling information
• Memory management info (page tables, segment tables)
• Accounting information (CPU time, limits)
• I/O status information (open files, devices)
PCB ensures that a process can resume correctly after a context switch.
Page 3 of 12
Context Switching
➢ Context switching occurs when the CPU switches from one process to another.
OS actions during context switch:
• Save the context of the current process in its PCB
• Load the context of the new process
• Update scheduling queues
➢ Context switching creates overhead because the CPU performs switching instead of
executing instructions.
Process Scheduling Queues
a. Job Queue
Contains all processes in the system.
b. Ready Queue
Processes waiting for CPU.
c. Device Queue
Processes waiting for I/O devices.
Movement:
New → Ready → Running → Waiting → Ready → Terminated
Page 4 of 12
PROCESS SCHEDULING
• Process Scheduling is the operating system function that selects which process from
the Ready Queue should run next on the CPU.
• It ensures efficient CPU use, fairness, and fast response.
1. CPU–I/O Burst Cycle
A program alternates between:
• CPU bursts → executing instructions
• I/O bursts → waiting for I/O (disk, input, output)
CPU → I/O → CPU → I/O → … → Termination
Because processes frequently wait for I/O, the OS schedules other processes to use CPU
during this time.
2. Types of Schedulers
a) Long-Term Scheduler (Job Scheduler)
• Controls degree of multiprogramming
• Selects which processes are admitted to the system
• Present mainly in batch systems
• Runs infrequently
b) Short-Term Scheduler (CPU Scheduler)
• Selects a process from the Ready Queue
Page 5 of 12
• Decides which process runs next on the CPU
• Runs very frequently (milliseconds)
• Implements CPU scheduling algorithms (FCFS, SJF, RR, etc.)
c) Medium-Term Scheduler
• Handles swapping (suspending and resuming processes)
• Improves memory use
• Converts processes between READY ↔ SUSPENDED states
3. Preemptive vs Non-Preemptive Scheduling
Non-Preemptive Scheduling
• Once a process gets the CPU, it keeps it until:
o It finishes or
o It voluntarily waits (I/O)
Examples: FCFS, non-preemptive SJF, non-preemptive Priority
Preemptive Scheduling
• OS can take back the CPU from a running process
Page 6 of 12
• Used in time-sharing and interactive systems
• Provides better responsiveness
Examples: Round Robin, SRTF, preemptive Priority, MLFQ
4. Scheduling Criteria
• CPU Utilization → keep CPU busy
• Throughput → processes completed per unit time
• Turnaround Time → submission → completion
• Waiting Time → time spent in Ready Queue
• Response Time → time to first response
• Fairness → avoid starvation
5. Dispatcher
The dispatcher gives control of CPU to the process chosen by the scheduler.
It performs:
• Context Switch
• Switches to user mode
• Jumps to correct instruction address
Dispatch Latency = time needed to stop one process and start another.
6. Scheduling Algorithms
Page 7 of 12
• FCFS
• Shortest Job First (SJF)
• Shortest Remaining Time First (SRTF)
• Priority Scheduling
• Round Robin (RR)
• Multilevel Queue
• Multilevel Feedback Queue (MLFQ)
• Real-Time Scheduling (EDF, RMS)
Operations on Processes
Operating systems perform various operations on processes to manage their lifecycle and
execution.
1. Process Creation
• A process may create another process.
• The creating process is called the parent and the created one is called the child.
Reasons for Process Creation
• New program execution
• User request
Page 8 of 12
• Batch job initiation
• System initialization
What happens during creation?
The OS:
• Allocates memory
• Creates a Process Control Block (PCB)
• Assigns unique PID
• Loads program into memory
• Links parent–child relationship
Process Creation System Call
• fork() in UNIX
• CreateProcess() in Windows
2. Process Termination
A process finishes execution when:
• It completes normally
• It encounters an error
• It is killed by another process (kill, exit)
• Parent terminates (some OSs use cascading termination)
Termination cleans:
• Open files
• Memory
• PCB
• CPU allocations
3. Process Suspension
A process may be temporarily stopped without being terminated.
Two Types
• Suspended ready – paused but ready to run
• Suspended waiting – paused while waiting for an event
Reasons
• Memory shortage
Page 9 of 12
• OS swapping
• Debugging
• Parent request
4. Process Resumption
Suspended processes can be resumed and moved back to the Ready Queue.
5. Process Cooperation
Processes may cooperate to share data.
Mechanisms
• Shared memory- Shared Memory is an IPC (Inter-Process Communication)
mechanism where two or more processes share a region of memory to exchange
data.
• Message passing- Message Passing is an IPC mechanism in which processes
communicate by sending and receiving messages, without sharing memory.
• Pipes- A pipe is a unidirectional communication channel used to transfer data from
one process to another.
• Sockets- A socket is an endpoint for communication between two processes.
Processes can be on the same machine or on different machines across a network.
6. Process Synchronization
Ensures coordinated execution to avoid race conditions.
Common mechanisms:
• Semaphores- A semaphore is a synchronization tool used to control access to shared
resources in a concurrent system
• Mutexes- A mutex (Mutual Exclusion Lock) is a synchronization mechanism used to
ensure that only one thread/process can enter the critical section at a time.
• Monitors- A monitor ensures that only one process/thread can be active inside it at
a time. Monitors simplify synchronization compared to semaphores because locking
is automatic, reducing programmer errors.
• Condition variables- A condition variable is a synchronization mechanism used
inside monitors or with mutexes to allow threads to wait for certain conditions to
become true.
7. Process Communication (IPC)
Processes exchange data using:
• Message queues- A Message Queue is an IPC mechanism that allows processes to
send and receive messages stored inside a queue maintained by the operating
system.
Page 10 of 12
• Shared memory
• Pipes
• Signals- A signal is a software interrupt sent to a process or thread to notify it that an
event has occurred.
• RPC- Remote Procedure Call (RPC) is a communication mechanism that allows a
program to call a function on another machine as if it were calling a local function.
Process Operations
Inter-Process Communication (IPC)
Inter-Process Communication (IPC) is a mechanism provided by the operating system that
allows processes to exchange data, coordinate actions, and synchronize their operations.
In modern computing systems, multiple processes often run simultaneously and need to
communicate. IPC enables communication in:
• Single processor systems
• Multiprocessor systems
• Distributed systems
Why IPC is Needed?
Processes need to communicate for:
• Sharing data
• Coordinating task completion
• Synchronizing access to shared resources
• Supporting client–server communication
• Enabling parallel and distributed computing
Example:
A web browser (client) communicates with a web server (process on remote machine).
Page 11 of 12
Two Major IPC Models
1. Message Passing
• Processes communicate by sending and receiving messages.
• No shared memory is used.
Characteristics:
• Useful in distributed systems
• Simple and modular
• Kernel manages message queues
Examples:
• send() and receive() calls
• Message queues
• Mailboxes/ports
• Sockets
2. Shared Memory
Two or more processes share a region of memory.
Characteristics:
• Fastest IPC method
• Requires synchronization (semaphores, mutex)
• Suitable for large data exchange
Examples:
• POSIX shared memory (shmget(), shmat())
• Shared buffers between producer and consumer
Common IPC Mechanisms
1. Pipes
Unidirectional communication between related processes (parent-child).
• Example: Linux pipe (|) used in shell commands.
2. Named Pipes (FIFOs)
Communication between unrelated processes.
3. Message Queues
Page 12 of 12
Messages stored in FIFO or priority-based queues.
4. Shared Memory
Fast, but synchronization needed.
5. Semaphores
Used for synchronization and preventing race conditions.
6. Signals
Simple notifications sent to processes (e.g., SIGINT, SIGKILL).
7. Sockets
Used for communication between processes on different machines (TCP/UDP).
8. Remote Procedure Calls (RPC)
A process calls a function on another machine.
IPC Examples
Example 1 – Pipe
ls | grep "test"
Output of ls is sent as input to grep.
Example 2 – Shared Memory
Producer writes data → Consumer reads data.
Example 3 – Socket Communication
A browser connects to a web server using TCP sockets.
Inter-Process Communication