Unit 1 Overview: Operating systems - structure, operations, components, types,
services, user interfaces. System calls, system programs, system boot . Process
management: Processes concept, scheduling, operations on processes, interprocess
communications. IPC Methods , pipes , popen , pclose functions , Co - Processes ,
FIFOS , Message Queues , Shared Memory , Stream pipes , Threads single- and
multi threaded processes .
1. Operating System – Overview
Definition
An Operating System (OS) is system software that acts as an interface between the user
and the hardware, managing computer resources and providing services to programs.
2. Structure of Operating System
OS Structure refers to how OS components are organized.
Types of OS Structures
1. Monolithic Structure
o Entire OS runs in kernel mode.
o Fast but difficult to maintain.
o Example: UNIX
2. Layered Structure
o OS divided into layers.
o Each layer uses services of lower layers.
o Easy debugging and maintenance.
3. Microkernel Structure
o Minimal kernel functionality.
o Services like file system run in user space.
o Example: Mach OS
4. Modular Structure
o Uses loadable kernel modules.
o Flexible and efficient.
o Example: Linux
3. Operations of an Operating System
• Interrupt handling
• Process scheduling
• Memory management
• I/O operations
• File management
• Protection and security
4. Components of Operating System
1. Process Management
2. Memory Management
3. File System Management
4. I/O System Management
5. Secondary Storage Management
6. Protection System
7. Command Interpreter (Shell)
5. Types of Operating Systems
1. Batch OS
2. Time Sharing OS
3. Distributed OS
4. Network OS
5. Real-Time OS
o Hard RTOS
o Soft RTOS
6. Multiprogramming OS
7. Multitasking OS
6. Operating System Services
• Program execution
• I/O operations
• File system manipulation
• Communication
• Error detection
• Resource allocation
• Accounting
• Protection & security
7. User Interfaces
1. Command Line Interface (CLI)
o Example: Terminal, Command Prompt
2. Graphical User Interface (GUI)
o Example: Windows, Linux GUI
3. Touch-based Interface
o Smartphones, tablets
8. System Calls
Definition
System calls provide an interface for user programs to request services from the OS
kernel.
Types of System Calls
1. Process Control
o fork(), exit(), wait()
2. File Management
o open(), read(), write(), close()
3. Device Management
4. Information Maintenance
5. Communication
6. Protection
9. System Programs
System programs provide a convenient environment for program development and
execution.
Types
• File manipulation
• Status information
• File modification
• Programming language support
• Program loading and execution
10. System Boot
Booting
Process of starting the computer and loading OS into memory.
Steps
1. Power ON
2. BIOS/UEFI runs
3. Boot loader loads OS
4. Kernel initializes
5. System ready for user
PROCESS MANAGEMENT
11. Process Concept
Process
A process is a program in execution.
Process States
1. New
2. Ready
3. Running
4. Waiting
5. Terminated
Process Control Block (PCB)
Contains:
• Process ID
• Process state
• Program counter
• CPU registers
• Memory limits
• I/O status
12. Process Scheduling
Scheduling
Selecting a process from ready queue to allocate CPU.
Schedulers
• Long-term scheduler
• Short-term scheduler
• Medium-term scheduler
13. Operations on Processes
• Creation (fork())
• Execution
• Suspension
• Termination (exit())
14. Inter Process Communication (IPC)
Definition
Mechanism that allows processes to communicate and synchronize.
Types
1. Shared Memory
2. Message Passing
IPC METHODS (IMPORTANT)
15. Pipes
• Used for communication between related processes.
• Unidirectional.
• Example: pipe()
16. popen() and pclose()
• popen() creates a pipe and runs a command.
• pclose() closes the pipe.
Used to read/write from another process.
17. Co-Processes
• Two processes execute concurrently.
• Communicate using pipes.
• Common in UNIX systems.
18. FIFOs (Named Pipes)
• Special file used for IPC.
• Can be used by unrelated processes.
• Persistent until deleted.
19. Message Queues
• Messages stored in queue.
• Processes communicate via messages.
• No shared address space needed.
20. Shared Memory
• Fastest IPC method.
• Processes share a common memory area.
• Requires synchronization.
21. Stream Pipes
• Data flows as continuous stream.
• Common in UNIX pipelines.
22. Threads
Thread
A lightweight process.
Benefits
• Faster context switching
• Shared memory
• Better CPU utilization
23. Single-threaded Process
• One thread per process
• Simple but inefficient
24. Multi-threaded Process
• Multiple threads within one process
• Better performance
• Example: Web servers
Advantages of Multithreading
• Responsiveness
• Resource sharing
• Economy
• Scalability
Unit 2 CPU scheduling - criteria, algorithms, multiple - processor scheduling. Process
synchronization - critical - section problem, semaphores, classic synchronization
problems, monitors.
PART A: CPU SCHEDULING
1. CPU Scheduling – Introduction
CPU Scheduling is the process of deciding which process gets the CPU when multiple
processes are in the ready state.
Objectives
• Maximize CPU utilization
• Improve system performance
• Reduce waiting and turnaround time
2. Scheduling Criteria
Used to evaluate and compare scheduling algorithms:
1. CPU Utilization – Keep CPU busy as much as possible
2. Throughput – Number of processes completed per unit time
3. Turnaround Time (TAT) – Completion time − Arrival time
4. Waiting Time (WT) – Time spent in ready queue
5. Response Time – Time from request to first response
6. Fairness – Equal CPU access
3. CPU Scheduling Algorithms
1. First Come First Serve (FCFS)
• Non-preemptive
• Processes executed in order of arrival
Advantages
• Simple
• No starvation
Disadvantages
• Convoy effect
• Poor response time
2. Shortest Job First (SJF)
• Executes process with shortest burst time
• Can be preemptive (SRTF) or non-preemptive
Advantages
• Minimum average waiting time
Disadvantages
• Difficult to predict burst time
• Starvation possible
3. Priority Scheduling
• CPU allocated based on priority
• Higher priority → earlier execution
Types
• Preemptive
• Non-preemptive
Problem
• Starvation
Solution
• Aging
4. Round Robin (RR)
• Time-sharing algorithm
• Fixed time quantum
Advantages
• Good response time
• Fair scheduling
Disadvantages
• High context switching if time quantum is small
5. Multilevel Queue Scheduling
• Ready queue divided into multiple queues
• Each queue has its own scheduling algorithm
6. Multilevel Feedback Queue
• Process can move between queues
• Used in modern OS
4. Multiple-Processor Scheduling
Used when more than one CPU is available.
Types
1. Asymmetric Multiprocessing
o One master CPU schedules others
2. Symmetric Multiprocessing (SMP)
o All processors are equal
o Common in modern systems
Issues
• Load balancing
• Processor affinity
• Cache consistency
PART B: PROCESS
SYNCHRONIZATION
5. Process Synchronization
Ensures correct execution of concurrent processes sharing data.
Why Needed?
• Prevent data inconsistency
• Avoid race conditions
6. Critical Section Problem
Critical Section: Part of code where shared data is accessed.
Requirements for Solution
1. Mutual Exclusion
2. Progress
3. Bounded Waiting
7. Semaphores
Definition
Semaphore is an integer variable used to control access to shared resources.
Types
1. Binary Semaphore (Mutex)
2. Counting Semaphore
Operations
• wait() / P()
• signal() / V()
Advantages
• Simple synchronization tool
Disadvantages
• Deadlock
• Starvation
• Programming errors
8. Classic Synchronization Problems
1. Producer–Consumer Problem
• Producer produces data
• Consumer consumes data
• Uses semaphores for synchronization
2. Readers–Writers Problem
• Multiple readers can read simultaneously
• Writer needs exclusive access
3. Dining Philosophers Problem
• Philosophers need two forks to eat
• Demonstrates deadlock and starvation
9. Monitors
Definition
High-level synchronization construct that provides mutual exclusion automatically.
Components
• Shared variables
• Procedures
• Condition variables (wait, signal)
Advantages
• Easier to use than semaphores
• Less error-prone
Disadvantages
• Language dependent
Semaphore vs Monitor (IMPORTANT)
Feature Semaphore Monitor
Level Low-level High-level
Error-prone Yes No
Mutual exclusion Manual Automatic
Complexity High Low