0% found this document useful (0 votes)
2 views62 pages

OS notes

An Operating System (OS) is system software that serves as an interface between users and computer hardware, managing processes, memory, files, devices, security, and providing user interfaces. There are various types of operating systems, including Batch, Multiprogramming, Time-Sharing, Real-Time, and Mobile OS, each with specific functionalities and use cases. Additionally, the OS provides services through system calls that allow user programs to request resources and perform operations on the hardware.

Uploaded by

akshaygodage1234
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views62 pages

OS notes

An Operating System (OS) is system software that serves as an interface between users and computer hardware, managing processes, memory, files, devices, security, and providing user interfaces. There are various types of operating systems, including Batch, Multiprogramming, Time-Sharing, Real-Time, and Mobile OS, each with specific functionalities and use cases. Additionally, the OS provides services through system calls that allow user programs to request resources and perform operations on the hardware.

Uploaded by

akshaygodage1234
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Unit 1 – Operating System

1. Operating System – Concept


Definition

An Operating System (OS) is system software that acts as an interface between the user
and computer hardware.

Simple Explanation

A computer has many hardware components like:

● CPU
● RAM
● Hard Disk
● Keyboard
● Mouse
● Printer

The user cannot directly control all these hardware components. The Operating System
manages the hardware and allows the user to use the computer easily.

Simple Example

When you open Google Chrome:

User → Operating System → Hardware

The OS tells the CPU, RAM, and other hardware what to do.

Examples of Operating Systems

● Windows
● Linux
● macOS
● Android
● iOS

Main Idea
USER

OPERATING SYSTEM

HARDWARE

CPU | RAM | DISK | KEYBOARD

2. Functions of Operating System


The main functions of an Operating System are:

1. Process Management

The OS manages all running programs and processes.

Example:
If you open Chrome, WhatsApp and MS Word at the same time, the OS manages all of them.

2. Memory Management

The OS manages the computer's RAM (main memory).

It:

● Allocates memory to programs.


● Releases memory when programs are closed.
● Keeps track of which memory is being used.

Example:
When you open a large application, the OS gives it the required RAM.

3. File Management

The OS manages files and folders.

It allows users to:

● Create files
● Delete files
● Rename files
● Copy files
● Move files
● Organize files into folders

Example:
Windows File Explorer is used for file management.

4. Device Management

The OS manages hardware devices connected to the computer.

Examples:

● Keyboard
● Mouse
● Printer
● Scanner
● Hard disk

The OS uses device drivers to communicate with hardware.

5. Security Management

The OS protects the computer and user data from unauthorized access.

Example:

● Password/PIN
● User accounts
● File permissions

6. User Interface

The OS provides an interface through which users can interact with the computer.

Two common types are:

GUI – Graphical User Interface


Example: Windows desktop, icons and menus.
CLI – Command Line Interface
Example: Linux Terminal, Windows Command Prompt.

7. Resource Management

The OS manages computer resources such as:

● CPU
● RAM
● Storage
● Input/Output devices

It decides which program gets which resource and when.

8. Error Management

The OS detects and handles errors in the computer system.

Example:
If a device is not working properly, the OS may display an error message.

Types of Operating Systems


There are different types of Operating Systems based on how they manage programs, users,
time, and resources.

1. Batch Operating System


Definition

A Batch Operating System executes a group (batch) of similar jobs one after another
without direct interaction from the user.

Simple Explanation

In this system, the user gives many jobs to the computer. The OS collects them into a batch
and processes them one by one.
Example

Suppose a company has 1000 employee salary calculations.

Instead of calculating each salary manually:

1000 Salary Jobs



BATCH

Operating System

Process one by one

Advantages

● Processes many jobs efficiently.


● Less user interaction is required.
● Good for large repetitive tasks.

Disadvantages

● No direct interaction with the user.


● Difficult to debug errors.
● A job may have to wait for previous jobs to finish.

Examples

● Payroll processing
● Bank statement generation
● Electricity bill processing

2. Multiprogramming Operating System


Definition

A Multiprogramming Operating System keeps multiple programs in memory at the same


time and allows the CPU to work on them.

Simple Explanation
The CPU is very fast. If one program is waiting for input/output, the CPU can work on another
program.

RAM
┌─────────────────┐
│ Program 1 │
│ Program 2 │
│ Program 3 │
└─────────────────┘

CPU

Executes programs

Example

You are running:

● MS Word
● Chrome
● Calculator

If Word is waiting for data, the CPU can work on Chrome.

Advantages

● Better CPU utilization.


● More than one program can be kept in memory.
● Reduces CPU idle time.

Disadvantages

● Requires more memory.


● OS becomes more complex.
● Memory management is required.

3. Time-Sharing Operating System


Definition
A Time-Sharing Operating System allows multiple users or programs to use the CPU by
giving each one a small amount of CPU time.

Simple Explanation

The CPU gives each task a small time slice called a time quantum.

CPU

User 1 → small time

User 2 → small time

User 3 → small time

User 1 → again

Because switching happens very quickly, users feel that they are using the computer
simultaneously.

Example

A computer lab where many users access a central computer system.

Advantages

● Fast response to users.


● Supports multiple users.
● CPU is used efficiently.

Disadvantages

● Requires more CPU and memory management.


● Security can be difficult.
● System can become slow if too many users are connected.

4. Real-Time Operating System (RTOS)


Definition
A Real-Time Operating System is an OS that processes data and gives a response within a
specific time limit.

Simple Explanation

In a real-time system, time is very important. The system must respond quickly and correctly.

Examples

● Airbag system in a car


● Medical equipment
● Aircraft control systems
● Industrial robots
● Traffic control systems

Example
Sensor detects danger

RTOS

Immediate response

Airbag opens

Types of Real-Time Systems

1. Hard Real-Time System


The response must be completed within the specified deadline.

Example: Airbag system.

2. Soft Real-Time System


A delay is undesirable but not usually catastrophic.

Example: Video/audio streaming.

Advantages

● Very fast response.


● Reliable for time-critical applications.
● Suitable for control systems.

Disadvantages
● Expensive to develop.
● Complex.
● Requires highly reliable hardware/software.

5. Mobile Operating System


Definition

A Mobile Operating System is an operating system designed specifically for mobile devices
such as smartphones and tablets.

Simple Explanation

It manages mobile hardware and provides an environment to run mobile applications.

Examples

● Android
● iOS

Main Functions

● Manages touchscreen.
● Manages mobile applications.
● Manages battery.
● Manages camera, microphone and sensors.
● Provides security.
● Manages Wi-Fi, Bluetooth and mobile networks.

Example
Mobile User

Mobile Operating System
↙ ↓ ↘
Apps Hardware Network

Advantages

● Easy to use.
● Supports mobile applications.
● Provides touch-based interface.
● Supports wireless communication.

Disadvantages

● Limited battery life.


● Limited hardware resources compared with PCs.
● Security risks from malicious applications.

Quick Comparison
Type Main Idea Example

Batch OS Jobs are processed in batches Payroll processing

Multiprogramming OS Multiple programs kept in memory Multiple applications

Time-Sharing OS CPU time is shared between Multi-user systems


users/programs

Real-Time OS Gives response within a fixed time Airbag system

Mobile OS Designed for mobile devices Android, iOS

Command Line Operating Systems and


GUI-Based Operating Systems
Operating systems can also be classified based on how the user interacts with the
computer.

1. Command Line Operating System (CLI)


Definition

A Command Line Interface (CLI) is an interface where the user interacts with the computer by
typing commands using the keyboard.

Simple Explanation

There are no buttons or graphical icons to click. The user types a command, and the computer
executes it.

Basic Structure
User

Types Command

Command Line Interface

Operating System

Hardware

Examples

● DOS (Disk Operating System)


● UNIX

Example

In DOS, a user can type:

dir

The dir command displays files and folders.

Another example:

cd documents

This command changes the current directory to the Documents folder.

Advantages of CLI

1. Fast for experienced users.


2. Requires less memory.
3. Useful for system administration.
4. Can perform tasks using commands quickly.

Disadvantages of CLI

1. Commands must be remembered.


2. Difficult for beginners.
3. Typing mistakes can cause errors.
4. No graphical interface.

2. GUI-Based Operating System


Definition

A Graphical User Interface (GUI) allows users to interact with the computer using windows,
icons, menus, buttons and a mouse/touchpad.

Simple Explanation

Instead of typing commands, the user can click icons and buttons to perform tasks.

Basic Structure
User

Mouse / Keyboard / Touch

GUI

Operating System

Hardware

Examples

● Windows
● Linux
● macOS (Mac OS)

Example

To open a folder, instead of typing a command, you can simply:


Double-click → Folder → Open

Advantages of GUI

1. Easy to learn and use.


2. No need to remember many commands.
3. Uses icons, menus and buttons.
4. User-friendly.
5. Suitable for beginners.

Disadvantages of GUI

1. Requires more memory and processing power.


2. Can be slower than CLI for some tasks.
3. More graphical resources are required.

CLI vs GUI
Feature CLI GUI

Full Form Command Line Interface Graphical User Interface

Interaction Commands Icons, menus, buttons

Input Mainly keyboard Mouse, keyboard, touch

Ease of use Difficult for beginners Easy

Memory requirement Low Higher

Examples DOS, UNIX Windows, Linux, macOS

Speed for expert Very fast Generally slower for command-based


users tasks
Operating System Services and System
Calls
1. Services of Operating System
Definition

Operating System Services are the facilities provided by the OS to make it easy for users and
application programs to use the computer.

Simple Explanation

The OS works like a manager. It provides different services to programs and users.

Main Services of Operating System

1. Program Execution

The OS helps to load, run and stop programs.

Example:
When you open Chrome, the OS loads Chrome into memory and starts it.

2. Input/Output Operations

The OS manages input and output devices.

Examples:

● Keyboard
● Mouse
● Printer
● Monitor
● Disk

Example:
When you type using a keyboard, the OS manages the input.

3. File System Management


The OS manages files and directories.

It allows us to:

● Create files
● Delete files
● Open files
● Read/write files
● Rename files

4. Communication

The OS allows different processes or computers to exchange information.

Example:
Two programs running on a computer may need to communicate with each other.

5. Error Detection

The OS detects errors in:

● CPU
● Memory
● Storage
● Input/output devices
● Programs

It may display an error message or take corrective action.

6. Resource Allocation

The OS distributes computer resources among different programs.

Resources include:

● CPU
● Memory
● Storage
● I/O devices
Example:
If multiple programs need CPU time, the OS decides which program gets the CPU.

7. Protection and Security

The OS protects data and resources from unauthorized access.

Examples:

● Passwords
● User accounts
● File permissions

8. User Interface

The OS provides a way for users to interact with the computer.

Types:

● CLI – Command Line Interface


● GUI – Graphical User Interface

2. System Call
Concept of System Call
Definition

A System Call is a mechanism through which a user program requests a service from the
Operating System.

Simple Explanation

A normal application cannot directly access certain hardware or OS resources.

So, the application requests the OS through a system call.

Simple Example
Suppose a program wants to read a file.

Application Program

System Call

Operating System

File / Disk

The program says:

"OS, please read this file for me."

The OS performs the operation and returns the result to the program.

3. Why are System Calls Used?


System calls are used when a program needs OS services such as:

● Creating a process
● Opening a file
● Reading a file
● Writing to a file
● Allocating memory
● Communicating with another process
● Accessing devices

4. Types of System Calls


There are mainly five important types of system calls.

1. Process Control
Used to create, execute and terminate processes.

Examples:
● Create process
● End process
● Load program
● Execute program
● Wait for a process

Example:
When you start a program, the OS creates a process for it.

2. File Management
Used to manage files and directories.

Examples:

● Create file
● Open file
● Read file
● Write file
● Close file
● Delete file

Example:

Program → Open File System Call → OS → File

3. Device Management
Used to control and access hardware devices.

Examples:

● Request a device
● Release a device
● Read from a device
● Write to a device

Example:
A program requests the OS to send data to a printer.
4. Information Maintenance
Used to get or change system information.

Examples:

● Get system time


● Get date
● Get process information
● Get system information
● Set system information

Example:
An application asks the OS for the current date and time.

5. Communication
Used for communication between processes or systems.

Examples:

● Send message
● Receive message
● Create communication connection
● Share information between processes

Example:
Two processes exchange data using communication system calls.

Diagram of System Call


USER

APPLICATION

SYSTEM CALL

OPERATING SYSTEM

HARDWARE

Easy Trick to Remember Types

P–F–D–I–C

● P → Process Control
● F → File Management
● D → Device Management
● I → Information Maintenance
● C → Communication

Short Exam Answer

System Call:
A system call is a mechanism used by a user program to request services from the Operating
System.

Types of System Calls:

1. Process Control
2. File Management
3. Device Management
4. Information Maintenance
5. Communication

Operating System Components


The Operating System (OS) is divided into different components. Each component manages a
specific part of the computer system.

The main components are:

1. Process Management
2. Main Memory Management
3. File Management
4. I/O Management
5. Secondary Storage Management

1. Process Management
Definition

Process Management is the function of the OS that manages all running


programs/processes.

Simple Explanation

A process is a program that is currently running.

The OS:

● Creates processes
● Deletes processes
● Schedules processes
● Suspends and resumes processes
● Allocates CPU to processes

Example

If you open:

Chrome + MS Word + Calculator

All three are running processes. The OS decides which process gets CPU time and when.

Simple Diagram
Operating System

Process Management
↙ ↓ ↘
Chrome Word Calculator

2. Main Memory Management


Definition

Main Memory Management manages the computer's RAM.

Simple Explanation

RAM is limited. Many programs need RAM at the same time.


The OS decides:

● Which program gets memory


● How much memory it gets
● Which memory is currently being used
● When memory should be released

Example

If Chrome requires 500 MB RAM, the OS allocates the required memory to Chrome.

When Chrome is closed, the OS can make that memory available for another program.

Simple Diagram
RAM
┌──────────────────┐
│ Chrome │
│ MS Word │
│ Operating System │
│ Free Memory │
└──────────────────┘


Memory Management

3. File Management
Definition

File Management is the OS component responsible for managing files and directories
(folders).

Simple Explanation

The OS helps users and programs store and organize data.

It performs operations such as:

● Create files
● Delete files
● Open files
● Read files
● Write files
● Rename files
● Create/delete folders

Example

When you create:

Documents

Student [Link]

The OS manages the file and its location on storage.

4. I/O Management
I/O = Input/Output

Definition

I/O Management manages communication between the computer and input/output devices.

Input Devices

● Keyboard
● Mouse
● Scanner
● Microphone

Output Devices

● Monitor
● Printer
● Speaker

Simple Explanation

The OS controls how data enters and leaves the computer.

Example
When you type:

Keyboard → OS → Application

When you print a document:

Application → OS → Printer

The OS manages this communication.

5. Secondary Storage Management


Definition

Secondary Storage Management manages permanent storage devices such as hard disks
and SSDs.

Examples

● HDD
● SSD
● USB drive
● Memory card

Simple Explanation

RAM is temporary memory, but secondary storage is used to store data permanently.

The OS manages:

● Free space
● Storage allocation
● File locations
● Disk scheduling

Example

When you save a file:

Application

Operating System

SSD / HDD

File Stored Permanently

Quick Revision Table


Component Main Work Example

Process Management Manages running programs Chrome, Word

Main Memory Management Manages RAM Allocating RAM to Chrome

File Management Manages files/folders Create, delete, read files

I/O Management Manages input/output Keyboard, printer


devices

Secondary Storage Manages permanent storage HDD, SSD


Management

Easy Trick to Remember

P–M–F–I–S

P → Process Management
M → Main Memory Management
F → File Management
I → I/O Management
S → Secondary Storage Management

Unit 2 – Process Management


Processes: Process States and Process
Control Block (PCB)
1. Process
Definition

A process is a program that is currently being executed.

Simple Example

A program is stored on the computer:

[Link] → Program

When you open Chrome:

[Link] → Running → Process

So:

Program + Execution = Process

2. Process States
A process does not remain in the same state during its entire execution. It moves through
different states.

There are mainly 5 process states:

1. New
2. Ready
3. Running
4. Waiting/Blocked
5. Terminated

Process State Diagram

┌─────────┐
│ New │

└────┬────┘

┌─────────┐

┌──────→│ Ready │←──────┐

│ └────┬────┘ │

│ ↓ │

│ ┌─────────┐ │

│ │ Running │ │

│ └────┬────┘ │

│ ↙ ↘ │

│ ↓ ↓ │

┌─────────┐ I/O ┌────────────┐

│ Waiting │ │ Terminated │

└────┬────┘ └────────────┘

└────────→ Ready

3. Explanation of Each Process State


1. New State

The process is being created.

Example:
You click on MS Word to open it. The OS starts creating the process.
2. Ready State

The process is ready to execute but is waiting for the CPU.

Example:

Process A → Ready

Process B → Ready

Process C → Ready

They are waiting for their turn to use the CPU.

3. Running State

The process is currently executing on the CPU.

Example:
MS Word is currently executing instructions on the CPU.

4. Waiting / Blocked State

The process is waiting for something, usually an I/O operation or another event.

Example:

Process → Requests data from disk

Waiting

Data received

Ready
5. Terminated State

The process has completed its execution or has been stopped.

Example:
You close MS Word → Word process is terminated.

4. Process Control Block (PCB)


Definition

A Process Control Block (PCB) is a data structure maintained by the Operating System that
contains important information about a process.

Simple Explanation

Think of PCB as the identity card/report card of a process.

The OS uses the PCB to keep track of every process.

PROCESS

┌─────────────────┐

│ PCB │

├─────────────────┤

│ Process ID │

│ Process State │

│ Program Counter │

│ CPU Registers │

│ CPU Scheduling │

│ Memory Info │

│ I/O Information │
└─────────────────┘

5. Information Stored in PCB


1. Process ID (PID)

A unique number given to each process.

Example:

Chrome → PID 1050

Word → PID 2050

2. Process State

Stores the current state of the process.

For example:

● New
● Ready
● Running
● Waiting
● Terminated

3. Program Counter

Stores the address of the next instruction that the process needs to execute.

4. CPU Registers

Stores the current values of CPU registers related to the process.


5. CPU Scheduling Information

Contains information needed by the OS scheduler.

For example:

● Process priority
● Scheduling information

6. Memory Management Information

Contains information about the memory allocated to the process.

7. I/O Status Information

Contains information about the I/O devices and files being used by the process.

6. Why is PCB Important?


PCB helps the OS to:

● Identify a process.
● Track the process state.
● Manage CPU scheduling.
● Manage memory.
● Manage I/O.
● Perform context switching.

Simple Example of Context Switching

Suppose CPU is running Process A.

CPU → Process A

Save A's information in PCB


Load Process B information

CPU → Process B

The PCB allows the OS to save and restore the information needed to continue a process later.

Quick Revision
Process States

New → Ready → Running → Waiting → Ready → Running → Terminated

PCB

PCB = Process Control Block

It stores important information about a process:

PID + State + Program Counter + Registers + Scheduling + Memory + I/O

Easy Trick

P-S-P-C-S-M-I

● P → Process ID
● S → Process State
● P → Program Counter
● C → CPU Registers
● S → Scheduling Information
● M → Memory Information
● I → I/O Information

Process Scheduling
1. Process Scheduling
Definition

Process Scheduling is the method used by the Operating System to select a process from
the ready processes and give it the CPU.

Simple Explanation

Many processes may be waiting to use the CPU, but usually only one process can use a CPU
core at a time.

The OS uses a CPU Scheduler to decide which process should run next.

Process A ─┐

Process B ─┤

Process C ─┤ → Ready Queue → CPU Scheduler → CPU

Process D ─┘

2. Scheduling Queues
A scheduling queue is a list of processes waiting for a particular resource or stage of
execution.

There are mainly three important queues:

1. Job Queue

Contains all processes that are waiting to enter the system for execution.

New Processes

Job Queue

2. Ready Queue

Contains processes that are ready to run and waiting for the CPU.
P1 ─┐

P2 ─┤

P3 ─┤ → Ready Queue → CPU

P4 ─┘

3. Device Queue

Contains processes that are waiting for an I/O device.

Examples:

● Printer
● Disk
● Keyboard
● Network device

Process

I/O Request

Device Queue

I/O Device

3. Types of Schedulers
A scheduler is an OS component that selects processes for execution.

There are mainly three types of schedulers:

1. Long-Term Scheduler
Definition

The Long-Term Scheduler selects processes from the job queue and loads them into the
ready queue.

Simple Explanation

It decides which processes should enter the system for execution.

Job Queue

Long-Term Scheduler

Ready Queue

Main Purpose

Controls the number of processes in memory.

It is also called the Job Scheduler.

2. Short-Term Scheduler
Definition

The Short-Term Scheduler selects a process from the ready queue and gives it the CPU.

Simple Explanation

It decides:

"Which process should use the CPU now?"

Ready Queue

Short-Term Scheduler


CPU

Important Point

It runs very frequently, so it must be very fast.

It is also called the CPU Scheduler.

3. Medium-Term Scheduler
Definition

The Medium-Term Scheduler temporarily removes processes from memory and later brings
them back.

This is called swapping.

Simple Explanation

If memory becomes full, the OS may temporarily move a process out of memory.

Memory

Medium-Term Scheduler

Disk

Later → Memory

Main Purpose

● Controls memory usage.


● Reduces the number of processes in memory.
● Supports swapping.
4. Comparison of Schedulers
Scheduler Main Work Speed

Long-Term Job Queue → Ready Less frequent


Queue

Short-Term Ready Queue → CPU Very frequent

Medium-Term Swapping processes Occasionally

Easy Trick

Long → Enter
Short → CPU
Medium → Swap

5. Context Switch
Definition

A Context Switch is the process of saving the state of one process and loading the state of
another process.

Simple Explanation

Suppose the CPU is running Process A.

The OS wants to run Process B.

First, the OS saves Process A's information in its PCB and then loads Process B's information.

CPU


Process A

Save A's Context

PCB A

Load B's Context

PCB B

Process B

CPU

What is Saved?

The OS may save information such as:

● Program Counter
● CPU Registers
● Process State
● Other CPU-related information

This information is stored in the PCB.

6. Real-Life Example of Context Switching


Imagine a teacher is checking two students' notebooks.

Student A


Teacher saves where they stopped

Student B

Teacher checks B

Returns to Student A

Continues from where they stopped

Similarly, the CPU switches between processes and continues each process from where it
stopped.

Complete Process Scheduling Diagram


JOB QUEUE

Long-Term Scheduler

READY QUEUE

Short-Term Scheduler


CPU

↙ ↘

Running I/O Request

│ │

│ ↓

│ DEVICE QUEUE

│ │

│ ↓

└──────────→ READY

Medium-Term Scheduler can temporarily move processes between memory and secondary
storage through swapping.

⭐ Exam Revision

Scheduling Queues

1. Job Queue – All processes waiting to enter the system.


2. Ready Queue – Processes waiting for CPU.
3. Device Queue – Processes waiting for I/O devices.

Types of Schedulers

1. Long-Term Scheduler – Selects jobs to enter memory.


2. Short-Term Scheduler – Selects the next process for CPU.
3. Medium-Term Scheduler – Performs swapping.

Inter-Process Communication (IPC)


1. What is Inter-Process Communication?
Definition

Inter-Process Communication (IPC) is a mechanism that allows two or more processes to


communicate and exchange data with each other.

Simple Explanation

Sometimes, processes need to share information.

For example:

Process A ←──── Communication ────→ Process B

The Operating System provides IPC mechanisms to make this communication possible.

Why is IPC Needed?

IPC is used for:

● Sharing data between processes


● Sending information
● Synchronizing processes
● Improving cooperation between processes

There are two common IPC methods:

1. Shared Memory System


2. Message Passing System

2. Shared Memory System


Definition

In a Shared Memory System, two or more processes communicate by using a common area
of memory.

Simple Explanation

The OS creates a portion of memory that can be accessed by multiple processes.

Process A

┌───────────────┐

│ Shared Memory │

└───────────────┘

Process B

Process A can write data into shared memory, and Process B can read that data.

Example

Suppose Process A produces data and Process B needs that data.

Process A

Writes Data

Shared Memory

Reads Data

Process B

Advantages

● Very fast communication.


● Suitable for large amounts of data.
● Processes can directly access the shared area.

Disadvantages

● Processes must carefully coordinate access.


● Synchronization is required.
● Incorrect access can cause data inconsistency.
Real-Life Example

Think of a common whiteboard.

Two people can use the same whiteboard:

Person A → Whiteboard ← Person B

The whiteboard represents shared memory.

3. Message Passing System


Definition

In a Message Passing System, processes communicate by sending and receiving


messages through the Operating System.

Simple Explanation

Processes do not need to share the same memory. Instead, one process sends a message and
another process receives it.

Process A

│ Send Message

Operating System

│ Receive Message

Process B

Example

Process A sends:
"Data is ready."

Process B receives the message and starts processing the data.

4. Basic Operations of Message Passing


There are two main operations:

Send

One process sends a message.

Process A

send(message)

Receive

Another process receives the message.

Process B

receive(message)

5. Advantages of Message Passing


● Easy to implement for communication between processes.
● No shared memory is required.
● Useful for communication between processes on different computers.
● Provides better separation between processes.

Disadvantages

● Usually slower than shared memory.


● Communication requires OS involvement.
● Extra time may be needed to send and receive messages.
6. Shared Memory vs Message Passing
Feature Shared Memory Message Passing

Communication Common memory Messages

Speed Faster Generally slower

Memory Shared area required No shared memory


required

OS involvement Mainly during setup More involved

Synchronization Required Often simpler

Data transfer Direct access Send/Receive

Example Common memory area Sending messages

Easy Diagram
INTER-PROCESS COMMUNICATION

┌───────┴───────┐
↓ ↓

Shared Memory Message Passing

│ │

Common Area Send / Receive

│ │

Fast Sharing Message Based

⭐ Easy Way to Remember

Shared Memory

"Same memory → Share data"

Process A → [ Shared Memory ] ← Process B

Message Passing

"Send message → Receive message"

Process A → Message → Process B

Short Exam Answer

IPC:
Inter-Process Communication is a mechanism that allows processes to communicate and
exchange data with each other.

Types of IPC:

1. Shared Memory System – Processes communicate using a common memory area.


2. Message Passing System – Processes communicate by sending and receiving
messages.

Threads
1. What is a Thread?
Definition

A Thread is the smallest unit of execution within a process.

Simple Explanation

A process can contain one or more threads.

Think of a process as a restaurant and threads as workers working inside the restaurant.

PROCESS

┌─────────────┐

│ │

│ Thread 1 │

│ Thread 2 │

│ Thread 3 │

│ │

└─────────────┘

Example

When you use a web browser, different threads may handle:

● Loading a webpage
● Playing video
● Downloading a file
● Handling user input

2. Benefits of Threads
1. Responsiveness

If one thread is busy, another thread can continue working.

Example:
A browser can continue responding while a webpage is loading.
2. Resource Sharing

Threads of the same process share resources such as:

● Code
● Data
● Files
● Memory

3. Economy

Creating and managing threads generally requires less overhead than creating separate
processes.

4. Faster Execution

Multiple threads can execute concurrently and, on multicore systems, can run in parallel.

5. Better CPU Utilization

Threads can keep the CPU busy while another thread is waiting for I/O.

3. Types of Threads
There are two main types:

1. User-Level Threads
2. Kernel-Level Threads

4. User-Level Threads
Definition

User-level threads are managed by a user-level thread library, without direct management by
the OS kernel.

Simple Explanation

The application manages its own threads.

User Process

┌─────────────┐

│ Thread 1 │

│ Thread 2 │

│ Thread 3 │

└─────────────┘

User Thread Library

Kernel

Advantages

● Faster to create.
● Faster to switch between threads.
● Does not require frequent kernel involvement.

Disadvantages

● If one thread makes a blocking system call, the entire process may be blocked in many
user-level implementations.
● The kernel may not schedule individual user threads separately.

5. Kernel-Level Threads
Definition

Kernel-level threads are managed directly by the Operating System kernel.

Simple Explanation

The OS knows about and manages each thread.

Process

┌─────────────┐

│ Thread 1 │

│ Thread 2 │

│ Thread 3 │

└──────┬──────┘

Kernel

CPU

Advantages

● Kernel can schedule threads individually.


● If one thread is blocked, other threads may continue.
● Better support for multicore processors.

Disadvantages

● Thread creation can be more expensive.


● Thread switching can have more overhead because the kernel is involved.

6. User-Level vs Kernel-Level Threads


Feature User-Level Kernel-Level

Managed by User-level library OS Kernel

Speed Faster Relatively slower

Kernel Kernel may not know individual threads Kernel knows threads
awareness

Blocking Can block the whole process in many Other threads can
implementations continue

Overhead Low Higher

Multicore Limited in many-to-one model Better


support

7. Multithreading Models
A multithreading model describes the relationship between user threads and kernel threads.

The important models are:

1. Many-to-One
2. One-to-One
3. Many-to-Many
8. Many-to-One Model
Definition

In the Many-to-One model, many user-level threads are mapped to one kernel thread.

User Threads Kernel

─────────────

Thread 1 ───┐

Thread 2 ───┼────────→ Kernel Thread

Thread 3 ───┘

Simple Explanation

Many user threads share one kernel thread.

Advantage

● Thread management is fast.


● Simple to implement.

Disadvantage

● If one thread makes a blocking system call, the entire process may block.
● Cannot achieve true parallel execution of these threads on multiple CPU cores.

9. One-to-One Model
Definition

In the One-to-One model, each user thread is mapped to one kernel thread.

User Threads Kernel Threads

Thread 1 ─────────────→ Kernel Thread 1


Thread 2 ─────────────→ Kernel Thread 2

Thread 3 ─────────────→ Kernel Thread 3

Simple Explanation

Every user thread gets its own kernel thread.

Advantages

● If one thread blocks, other threads can continue.


● Supports parallel execution on multicore processors.

Disadvantage

Creating many threads can increase system overhead.

10. Many-to-Many Model


Definition

In the Many-to-Many model, many user-level threads are mapped to multiple kernel threads.

User Threads Kernel Threads

Thread 1 ────────┐

Thread 2 ────────┼────→ Kernel Thread 1

Thread 3 ────────┤

Thread 4 ────────┼────→ Kernel Thread 2

Thread 5 ────────┘ Kernel Thread 3

Simple Explanation

Many user threads can be mapped to a smaller or equal number of kernel threads.

Advantages
● Provides good concurrency.
● Can support parallel execution.
● Avoids creating a kernel thread for every user thread.

Disadvantage

● More complex to implement.

11. Comparison of Multithreading Models


Model Mapping Main Advantage Main Disadvantage

Many-to-One Many user → One Simple and fast No true parallelism; blocking can
kernel affect all

One-to-One One user → One Good parallelism Higher overhead


kernel

Many-to- Many user → Many Flexible and Complex


Many kernel efficient

⭐ Easy Trick to Remember


Many-to-One

Many → One

👥👥👥 → 🖥️

Many user threads share one kernel thread.


One-to-One

One → One

👤 → 🖥️

👤 → 🖥️

👤 → 🖥️

Each user thread gets one kernel thread.

Many-to-Many

Many → Many

👥👥👥👥 → 🖥️🖥️🖥️

Many user threads share multiple kernel threads.

⭐ Exam Revision
Thread: Smallest unit of execution within a process.

Benefits of Threads:

1. Responsiveness
2. Resource sharing
3. Economy
4. Faster execution
5. Better CPU utilization

Types:

● User-Level Threads
● Kernel-Level Threads

Multithreading Models:

● Many-to-One: Many user threads → One kernel thread


● One-to-One: One user thread → One kernel thread
● Many-to-Many: Many user threads → Multiple kernel threads
Process Commands in Operating System
These commands are commonly used in Linux/UNIX to view, control, and manage processes.

The important commands are:

top, ps, kill, wait, sleep, exit, nice

1. top Command

Definition

The top command is used to display currently running processes and system resource
usage.

Simple Explanation

It shows processes that are running in real time.

top

It displays:

● Process ID (PID)
● CPU usage
● Memory usage
● Process name
● Process status

Example

top

Use: To monitor running processes and CPU/memory usage.

2. ps Command
Definition

ps stands for Process Status.

It is used to display information about currently running processes.

Example

ps

Common command

ps -ef

This displays detailed information about processes.

Important information:

● PID
● User
● CPU time
● Command
● Process status

Difference between ps and top

ps top

Shows process information at a particular Continuously updates process


moment information

Static output Real-time monitoring

Useful for checking processes Useful for monitoring system activity


3. kill Command
Definition

The kill command is used to send a signal to a process.

It is commonly used to terminate a process.

Syntax

kill PID

Example

kill 1234

Here, 1234 is the Process ID.

Force termination

kill -9 1234

This sends a forceful termination signal.

Important: kill does not always mean "immediately delete a process"; it sends a
signal, and the process may handle some signals.

4. wait Command
Definition

The wait command makes a shell wait for a process to finish.

Simple Example

sleep 5 &

wait

Here:
● sleep 5 & starts a background process.
● wait makes the shell wait until that process finishes.

Simple Meaning

wait = Wait until the process completes.

5. sleep Command
Definition

The sleep command pauses execution for a specified amount of time.

Example

sleep 5

The command waits for 5 seconds before continuing.

Another example:

sleep 10

The process pauses for 10 seconds.

Simple Meaning

sleep = Temporarily pause execution.

6. exit Command
Definition

The exit command is used to terminate the current shell/session.

Example
exit

After executing it, the current terminal shell closes or returns to its parent shell.

Exit with status

exit 0

0 generally indicates successful completion.

exit 1

A non-zero value generally indicates an error or unsuccessful completion.

Simple Meaning

exit = End the current shell/session.

7. nice Command
Definition

The nice command is used to start a process with a specified scheduling priority
(niceness).

Simple Explanation

It allows you to tell the OS:

"Give this process relatively higher or lower CPU scheduling priority."

Example

nice -n 10 myprogram

The program starts with a niceness value of 10.

Important Point

On Linux, the nice value normally ranges from -20 to +19:


● -20 → Higher scheduling priority
● 0 → Default
● +19 → Lower scheduling priority

Simple Meaning

nice = Adjust the scheduling priority of a process.

Quick Revision Table


Command Purpose

top Monitor running processes in real time

ps Display process information

kill Send a signal to a process

wait Wait for a process to finish

sleep Pause execution for a specified time

exit Terminate the current shell/session

nice Start a process with a specified


niceness/priority

⭐ Easy Way to Remember


top → See processes
ps → Process status
kill → Send signal
wait → Wait for process
sleep → Pause
exit → End shell
nice → Set priority

You might also like