OS Chapter 1

Module 1: Introduction to Operating System


Syllabus

Introduction, System Components, Open-Source Operating Systems, Operating System Services, System Calls, Process Management- Process Structure, Process states, Types of Schedulers, Scheduling Criteria, Scheduling algorithms. Deadlock and Starvation- Principles of Deadlock, Deadlock Prevention, Deadlock Avoidance, Deadlock Detection and Recovery. Linux Environment, Fundamental Commands. System Shell and User Shells.


What is an Operating System?

A program that acts as an intermediary between a user of a computer and the computer hardware

Operating system goals:


Computer System Structure

Computer system can be divided into four components:

Pasted image 20251030054321.png


What Operating Systems Do

! 500
!Pasted image 20251030054945.png

--

! 400
Pasted image 20251030055502.png

Definition of OS


“The one program running at all times on the computer” is the kernel.

Everything else is either a system program (ships with the operating system) , or an application program.


Computer Startup

--
Pasted image 20251030060244.png

Pasted image 20251030060308.png


Computer System Organization

--


Interrupts


Direct Memory Access (DMA)


Computer-System Architecture

Symmetric Multiprocessing Architecture

Pasted image 20251107061108.png


A Dual-Core Design


Clustered Systems

--
Pasted image 20251107061439.png

--

--

--


Multiprogramming (Batch System)

--

--


Time Sharing (Multitasking)


Operating-System Operations

Dual-Mode Operation

--

Timer in Operating Systems


Computing Environments

--

Traditional Computing

--

Mobile Computing

--

Distributed Computing

--
Pasted image 20251107070405.png

--

Client-Server Computing

--
Pasted image 20251107070602.png

Peer-to-Peer (P2P) Computing

Virtualization

--
Pasted image 20251107071003.png

Assets/Pasted image 20251107071112.png

Cloud Computing

Real-Time & Embedded Systems


Operating System Services

--

User-Oriented Services

--

System-Oriented Services


System Calls

Programming Interface to OS Services

High-level languages like C/C++ provide interfaces to OS services.
Programs usually use an Application Programming Interface instead of calling system calls directly.

--
Access via APIs

APIs offer easier function calls and abstractions, reducing complexity and improving portability across systems.

--
Common APIs

Win32 API for Windows systems
POSIX API for UNIX/Linux/Mac OS X
Java API for programs running on the JVM

--

Example

Pasted image 20251119093652.png


System Call Mapping

Unique Call Numbers

Each system call has a specific number used to index a system-call table.

--

System Call Interface

Lookup and Execution

The system-call interface checks the table and invokes the corresponding kernel function.
It returns the status and any output produced by the call.

--

Programmer View

No Need to Know Internal Implementation

The programmer only needs to follow the API and understand the OS behavior.
Internal mechanics of the system call remain hidden.

--

API Abstraction

Run-Time Support Library

Most interaction with the OS is managed by a run-time support library that comes with the compiler.


Pasted image 20251119094244.png


Pasted image 20251119094410.png


C Program invoking printf()
Pasted image 20251119094541.png


Operating System Structure

A general-purpose operating system is a very large program.

Different structural approaches include:

--
MS-DOS Structure
Design Goal
MS-DOS was created to offer maximum functionality using minimal space.

--
Lack of Modularity
Organization
It was not divided into separate, well-defined modules.

--
Interface Characteristics
Poor Separation
Although some structure exists, the interfaces and functionality levels are not clearly separated.

--
Pasted image 20251119095426.png

--

Linux System Structure / Architecture

Pasted image 20251127124057.png


Gary Kildall

Early Background

Gary Kildall was an American computer scientist and pioneer of personal computing.
He created CP/M, the first widely adopted OS for microcomputers.

--

CP/M and Innovation

Breakthrough

CP/M provided a standard OS interface for early 8-bit machines.
It inspired future OS designs, including MS-DOS.

--

IBM Visits Digital Research

Missed Meeting

In 1980, IBM approached Digital Research to license CP/M for its upcoming PC.
A meeting failed due to scheduling and contract disagreements.

--

Microsoft Steps In

Bill Gates’ Opportunity

With no agreement from Digital Research, IBM turned to Microsoft.
Microsoft acquired QDOS, modified it, and delivered what became MS-DOS.

--

Why I Mentioned

Kildall is often discussed when explaining MS-DOS because:

--
Assets/Pasted image 20251119095726.png

--
Assets/Pasted image 20251119095739.png

--
Assets/Pasted image 20251119095748.png

--
Assets/Pasted image 20251119095911.png


What is a Process?

--

Program vs Process

Program

--

When Does a Program Become a Process?

--

Multiple Processes from One Program


Pasted image 20251125120005.png


Process States

--

Process States

--
Pasted image 20251125120107.png


Pasted image 20251125120208.png

--
Process Control Block (PCB) contains  Information associated with each process (also called task control block)

--

•Process state – running, waiting, etc

•Program counter – location of instruction to next execute

• CPU registers – contents of all process centric registers

•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

--
Pasted image 20251205104140.png


CPU Scheduling Basics

--

Scheduling Queues

--
Pasted image 20251125120355.png

--

Short-Term Scheduler

--

Long-Term Scheduler

--

Types of Processes


CPU Scheduling Metrics

--

Turnaround Time

Time a process takes from arrival to completion.

Formula:
Turnaround time = Completion time − Arrival time

--

Waiting Time

Time a process waits in the ready queue before CPU execution.

Formula:
Waiting time = Turnaround time − Burst time

--

Average Waiting Time

Average time all processes spend waiting in the ready queue.

Formula:
Average waiting time = (Total waiting time of all processes) / (Number of processes)

--

Response Time

Time from process arrival until its first CPU execution.

Formula:
Response time = Start time − Arrival time

--

Throughput

Number of processes completed per unit time.

Formula:
Throughput = Number of processes completed / Total execution time


Q1

Process Arrival Time Burst Time
P1 0 5
P2 2 3
P3 4 7
P4 6 2

--

Q2

Process Arrival Time Burst Time
P1 1 4
P2 3 6
P3 5 2
P4 7 8

--

Q3

Process Arrival Time Burst Time
P1 0 9
P2 1 5
P3 3 1
P4 4 4

--

Q4

Process Arrival Time Burst Time
P1 2 6
P2 4 3
P3 5 9
P4 8 2

--

Q5

Process Arrival Time Burst Time
P1 0 8
P2 1 2
P3 3 5
P4 6 4

Deadlock


Multiple Processes

Several processes run concurrently and compete for limited resources.

--

Resource Requests

A process asks for resources.
If unavailable, it moves to a wait state.

--

Wait State Issue

A waiting process may stay stuck if the resources it needs are held by other waiting processes.

--

Result

Processes may never resume — a situation that can lead to deadlock.


System Model

--

Resource Request Rule

A process must request a resource before using it and release it after use.

--

Resource Limits

A process cannot request more instances of a resource than the system actually has.

--

Example

If the system has 2 printers, no process can request 3 printers.


Deadlock Characterization

--

Deadlock occurs when processes are stuck waiting for resources held by each other, with no progress possible.

--

Four Necessary Conditions

  1. Mutual Exclusion – Resources are non-shareable.
  2. Hold and Wait – A process holds one resource and waits for another.
  3. No Preemption – Resources cannot be forcibly taken away.
  4. Circular Wait – A circular chain of processes exists, each waiting for a resource held by the next.

Resource Allocation Graph

--

Definition

A deadlock can be represented using a directed system resource-allocation graph.

--

Graph Structure

The graph has:

Vertex Types

Vertices are divided into two sets:

Request Edge

Pi → Rj
Process Pi has requested resource Rj and is waiting for it.

--

Assignment Edge

Rj → Pi
An instance of resource Rj is allocated to process Pi.

--

Edge Types

--
Process
Pasted image 20251129071607.png

--
Resource Type with 4 instances
Pasted image 20251129071633.png

--
Pi requests instance of Rj
Pasted image 20251129071732.png

--
Pi is holding an instance of Rj
Pasted image 20251129071829.png

--
Pasted image 20251127135039.png

--

RAG with deadlock

Pasted image 20251127135114.png

--
Graph With A Cycle But No Deadlock
Pasted image 20251129071924.png

--


Methods for Handling Deadlocks

--

1. Prevention / Avoidance

Use protocols that ensure the system never enters a deadlock state. (before occurance)

--

2. Detection & Recovery

Allow deadlocks to occur, then detect and recover from them. (after occurance)

--

3. Ignore Deadlocks

Ignore the problem and pretend that deadlocks never occur in the system; used by most operating systems, including UNIX


Deadlock Prevention

Restrain the ways request can be made

--


Deadlock Avoidance

Requires that the system has some additional a priori information available

--

--

--

--

Safe state

When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state

--

--

Safe, Unsafe, Deadlock State

Pasted image 20251129073341.png

--

Single instance of a resource type

Multiple instances of a resource type

--

Banker's algorithm

Q1
Total resources = (A=11, B=6, C=9, D=7)

Pasted image 20251205105134.png

--
Q2
Available = (A = 3, B = 2, C = 1, D = 2)

Pasted image 20251205105628.png


Refer https://os.surajgowda.in/scheduling-algo to verify answers