OS Notes by Piyush Slashbyte
OS Notes by Piyush Slashbyte
SLASH BY TE
SSC-BA NK
NOTES
SLASHBYTE | SSC-BANK
1 |
Infra Support (OS)
An Operating System can be defined as an interface between user and hardware. It is
responsible for the execution of all the processes, Resource Allocation, CPU management, File
Management and many other tasks.
The purpose of an operating system is to provide an environment in which a user can execute
programs in convenient and efficient manner.
2. Process Synchronization
3. Memory Management
4. CPU Scheduling
5. File Management
6. Security
Processes a batch of
Simple Batch Operating jobs sequentially without
IBM 7090 -
System user interaction during
execution.
Running multiple
programs on a single
Multi-programming Batch + Multi-
CPU, where the CPU IBM OS/360
Batch OS programming
switches between tasks
to maximize CPU usage.
Uses multiple
processors for executing
Multi-processing Multi-tasking + Multi-
tasks concurrently, UNIX, Linux
Operating System processing
improving speed and
reliability.
Manages
Network Operating communication and Windows Server, Novell
Networking capabilities
System resource sharing in a NetWare
networked environment.
A versatile OS
supporting multiple Multi-user + Multi-
UNIX UNIX, macOS, Solaris
users, multi-tasking, and tasking + Time-sharing
time-sharing features.
A UNIX-like OS offering
flexibility, multi-user Multi-user + Multi-
Linux support, multi-tasking, Ubuntu, Red Hat, Debian tasking + Time-sharing
time-sharing, and robust + Networking
networking capabilities.
Time-sharing: Ensures equitable distribution of CPU time across processes and users.
Networking: Provides robust tools and protocols for communication between devices.
Examples: File operations (open, read, write), process control (fork, exec), memory
management (malloc), etc.
2. Processes:
Definition: A process is an instance of a program that is currently being executed. It
contains its own address space, code, data, and system resources like open files.
Process Control Block (PCB): Stores information about the process, such as process ID,
state, program counter, and memory management information.
Attributes of a process
The Attributes of the process are used by the Operating System to create the process control
block (PCB) for each of them. This is also called context of the process. Attributes which are
stored in the PCB are described below.
General
Holds data generated during the
5 Purpose
execution of the process.
Registers
3. Threads:
Definition: A thread is the smallest unit of execution within a process. Multiple threads can
exist within a single process and share the same resources (memory, file descriptors) but
execute independently.
Types:
Benefits: Threads allow for better resource utilization and faster context switching than
processes.
1. Pipes
2. Shared Memory
3. Message Queue
4. Direct Communication
5. Indirect communication
6. Message Passing
7. FIFO
Pipe:-
The pipe is a type of data channel that is unidirectional in nature. It means that the data in this
type of data channel can be moved in only a single direction at a time.
Shared Memory:-
It can be referred to as a type of memory that can be used or accessed by multiple processes
simultaneously. It is primarily used so that the processes can communicate with each other.
Message Queue:-
In general, several different messages are allowed to read and write the data to the message
queue. In the message queue, the messages are stored or stay in the queue unless their
recipients retrieve them.
It is a type of mechanism that allows processes to synchronize and communicate with each
other. However, by using the message passing, the processes can communicate with each
other without restoring the hared variables.
Usually, the inter-process communication mechanism provides two operations that are as
follows:
send (message)
received (message)
In this type of communication process, usually, a link is created or established between two
communicating processes. However, in every pair of communicating processes, only one link
can exist.
Indirect Communication
Indirect communication can only exist or be established when processes share a common
mailbox, and each pair of these processes shares multiple communication links. These shared
links can be unidirectional or bi-directional.
FIFO:-
It is a type of general communication between two unrelated processes. It can also be
considered as full-duplex, which means that one process can communicate with another
process and vice versa.
1. Mutual Exclusion
2. Semaphore
4. Spinlock
Here’s a table with explanations of Mutual Exclusion, Semaphore, Barrier, and Spinlock:
A synchronization primitive
A printer pool where only 3
that controls access to To manage access to a
printers are available, and a
shared resources using a limited number of
Semaphore counting semaphore controls
counter. There are two resources by multiple
how many threads can use a
types: binary and counting threads or processes.
printer at a time.
semaphores.
A synchronization
To synchronize the In parallel processing, threads
mechanism that prevents
execution of multiple perform steps in stages, and
processes or threads from
Barrier threads, ensuring all they all must reach a "barrier"
proceeding until all involved
reach a common point before moving to the next
processes reach a certain
before continuing. stage.
point.
Key Points:
Mutual Exclusion ensures only one process can access critical sections at a time.
Semaphore manages access to resources using a counter, with binary or counting types.
Spinlock is a lock type where the process stays active, repeatedly checking for lock
availability.
Problems in Concurrency:
Mutex is used for mutual exclusion where only one thread can access a critical section
at a time, and it enforces ownership.
Binary Semaphore: A semaphore with only two values (0 or 1), used for mutual
exclusion to allow only one thread to access a resource at a time.
Single resource
Managing a pool of resources
Usage synchronization (e.g., mutual
(e.g., printers, buffers)
exclusion)
Semaphore Operations:
6. Deadlock:
Definition: Deadlock occurs when a set of processes are blocked because each process is
holding a resource and waiting for another resource held by a different process.
Hold and wait: A process holding one resource is waiting for others.
Circular wait: A circular chain of processes exists where each process is waiting for a
resource held by the next process.
Strategies Handling :
Strategy Description Pros Cons
OS ignores deadlock,
Deadlock Ignorance Simple, focuses on Deadlocks may occur,
assuming it doesn't
(Ostrich Algorithm) performance. requiring manual restart.
happen.
Prevents deadlock by
violating one of the four Prevents deadlock from May reduce system
Deadlock Prevention
necessary conditions occurring. performance.
(mutual exclusion, etc.).
Deadlock Detection & OS detects deadlock Detects and handles Causes downtime or
Recovery after it occurs and takes deadlock when it performance issues for
action (e.g., process occurs. recovery.
Deadlock Prevention: Techniques like resource allocation graphs, and methods like
resource ordering or timeout mechanisms can be used to avoid or detect deadlock.
Spooling
Spooling is a process where data is temporarily stored in a queue or buffer to be processed
later, typically by slower devices like printers. Multiple tasks can send their data to the spool,
which holds it until the device is ready to process it. This helps manage device access, prevent
delays, and enable multitasking.
Although, Spooling can be an effective approach to violate mutual exclusion but it suffers from
two kinds of problems.
2. After some point of time, there may arise a race condition between the processes to get
space in that spool.
Example:
In printing, print jobs are spooled, meaning they are stored in a queue and printed one after
another as the printer becomes available.
Banker’s Algorithm:
Real-Life Example of the Banker's Algorithm:
Imagine a bank with a limited amount of money (resources), and several customers
(processes) who want to withdraw money (request resources). The bank must ensure that it
always has enough money to meet future withdrawal requests without running out of funds
(deadlock).
Scenario:
Bank's Total Resources (Money): ₹1000
Customers' Requests:
The bank checks if this request is less than or equal to the total money available.
The bank checks if ₹300 is less than or equal to the remaining ₹500.
The bank checks if ₹200 is less than or equal to the remaining ₹200.
At every step, the bank ensures that after allocating the money, it still has enough funds to
cover all future withdrawals. The process continues in a way that ensures no customer will be
left waiting forever or cause a shortage of funds.
This is how the Banker's Algorithm works: it checks if resources can be allocated safely
(without running out) before giving them to customers, preventing deadlock.
7. Memory Management:
Definition: Memory management is the process by which an OS manages physical and
virtual memory. It ensures that processes have enough memory to execute and protects
the memory space of one process from another.
Paging: Divides physical memory into fixed-size blocks and maps them to logical
memory blocks.
Segmentation: Divides memory into segments based on logical divisions like code,
data, etc.
Memory Allocation: Includes strategies like First Fit, Best Fit, and Worst Fit for
assigning memory to processes.
8. Virtual Memory:
Definition: Virtual memory allows the system to use more memory than what is physically
available by using disk space as an extension of RAM. It gives the illusion of a larger main
memory.
Components:
Swapping: Involves moving data between RAM and disk (swap space) to manage
memory effectively.
Advantages: Provides processes with the illusion of a large, contiguous memory space
and isolates processes from each other’s memory.
Process Management in OS
A Program does nothing unless its instructions are executed by a CPU. A program in execution
is called a process. In order to accomplish its task, process needs the computer resources.
Process States
PCB: Process Control Block- Every process has a PCB. A PCB is a data structure. It is a big look
up table. PCB is also called as Process Descriptor.
Process Queues
2. Ready Queue
Ready queue is maintained in primary memory. The short term scheduler picks the job from the
ready queue and dispatch to the CPU for the execution.
3. Waiting Queue
When the process needs some IO operation in order to complete its execution, OS changes the
state of the process from running to waiting. The context (PCB) associated with the process
gets stored on the waiting queue which will be used by the Processor when the process
finishes the IO.
CT - AT = WT + BT
TAT = CT - AT
1. Arrival Time
The time at which the process enters into the ready queue is called the arrival time.
2. Burst Time
The total amount of time required by the CPU to execute the whole process is called the Burst
Time. This does not include the waiting time. It is confusing to calculate the execution time for
3. Completion Time
The Time at which the process enters into the completion state or the time at which the
process completes its execution, is called completion time.
4. Turnaround time
The total amount of time spent by the process from its arrival to its completion, is called
Turnaround time.
5. Waiting Time
The Total amount of time for which the process waits for the CPU to be assigned is called
waiting time.
6. Response Time
The difference between the arrival time and the time at which the process first gets the CPU is
called Response Time.
7. Throughput:
The amount of work that is completed per unit time. STS wants high throughput.
T=n/L
CPU Scheduling
In uniprogramming systems, the CPU remains idle during I/O operations, wasting time. In
contrast, multiprogramming systems use CPU scheduling and context switching to keep the
CPU busy by switching between processes in the ready queue.
[Context switching occurs when the CPU saves the current process's state (PCB) and loads
another process's state, enabling multitasking without losing process progress.]
3. Maximum throughput
Scheduling
Description Advantages Disadvantages
Algorithm
Processes are divided into Allows for a mix of Complex to manage and
Multilevel Queue different priority queues; scheduling algorithms can lead to issues if
Scheduling each queue has its own (e.g., FCFS for foreground, processes are stuck in the
scheduling algorithm. RR for background). wrong queue.
FCFS :
The
convoy effect refers to a situation in which processes or threads in a system are delayed or
slowed down because they must wait for other processes that are currently holding resources.
This creates a "chain" of delays, as slower or blocked processes prevent others from making
progress, leading to inefficiency
Shortest Job First (SJF):
It is particularly efficient when job lengths are similar because it minimizes average waiting
time by executing the shortest jobs first. If job lengths vary significantly, it may lead to longer
jobs being delayed, causing starvation of those processes.
Memory Management
Memory Management refers to the process of efficiently managing a computer's memory
resources, ensuring that programs and processes have access to the memory they need while
optimizing the system's overall performance.
A small, high-
speed memory
located close to Small (KB to CPU cache,
Cache Memory Very Fast Expensive
the CPU, stores MB) L1/L2 cache
frequently
accessed data.
Primary
memory used
Main Memory by the CPU to DRAM, SRAM,
Fast Moderate (GB) Less Expensive
(RAM) store running DDR4 RAM
processes and
data.
Permanent
Hard Drives,
Secondary storage used
Slow Large (TB) Cheap SSDs, Optical
Storage for long-term
Disks
data storage.
Key Differences:
Speed: Cache is the fastest, followed by main memory, with secondary storage being the
slowest. Main cache disadvantage: limited size.
Capacity: Secondary storage offers the largest capacity, while cache memory is the
smallest.
Cost: Cache memory is the most expensive per GB, followed by main memory, and
secondary storage is the cheapest.
Partitioning
It is one of the strategies used to implement memory management. It divides the system's
memory into blocks or partitions, making it easier to allocate and manage memory for
processes. The way memory is partitioned affects how well memory management works.
Dynamic Partitioning:
Memory is divided into partitions of varying sizes as needed, based on the size of the
processes. This helps reduce internal fragmentation, but can cause external
fragmentation (unused memory scattered between allocations). Memory management
includes techniques like compaction to solve fragmentation problems.
In paging, the smallest unit of virtual memory (the address space of a process) is
called a page.
Fragmentation:
Type of
Description Where it Occurs Example Solution
Fragmentation
Wasted space
Small free memory - Compaction (move
between Dynamic
blocks scattered memory to make
External allocations, making partitioning,
(1KB, 2KB), unable contiguous space)
Fragmentation it hard to find variable memory
to allocate a 4KB - Paging/Segmentation
contiguous free allocation
process. - Memory pooling
memory blocks.
Paging:
Definition: A memory management scheme that divides memory into fixed-size units
called pages. This eliminates the need for contiguous memory allocation.
Purpose: Helps manage virtual memory efficiently by breaking memory into smaller
chunks, allowing non-contiguous allocation.
Page Replacement
Description Advantages Disadvantages
Algorithm
Optimal (OPT) Replaces the page that Provides the minimum Not feasible in practice
will not be used for the number of page faults because it requires
Thrashing is a situation in which the operating system spends a significant amount of time
swapping data between main memory (RAM) and secondary storage (e.g., hard disk or swap
space), instead of executing the actual processes. This happens when the system’s physical
memory is so over-committed that it cannot keep up with the demands of running processes,
leading to excessive page faults and swapping.
Paging is primarily used in virtual memory management, while memory pooling is used to
efficiently allocate memory for uniform objects.
- Faster read/write
- Expensive.
speeds.
Flash memory with no - Lower storage
SSD (Solid State Drive) - More durable.
moving parts. capacity compared to
- Lower power
HDD.
consumption.
- Centralized data
- Slower data access
management.
NAS (Network Attached Storage device compared to SAN.
- Scalable storage.
Storage) connected to a network. - May require additional
- Easy file sharing
configuration.
across devices.
Ensures even
Distributes incoming
distribution of traffic to
Load Balancer network traffic across AWS ELB, F5 Big-IP
maintain performance
multiple servers.
and uptime.
Connecting
Connects devices Uses MAC devices like
Switch Layer 2 (Data Link)
within a network addresses computers and
printers in a LAN
Older networks,
Broadcasts data to
Sends data to all connects multiple
Hub all devices in a Layer 1 (Physical)
ports devices in a small
network
network
Key Differences:
Router: Routes between networks using IP addresses.
High throughout
SCAN scheduling
C-SCAN scheduling
LOOK Scheduling
C-LOOK scheduling
Scan Algorithm
It is also called as Elevator Algorithm. In this algorithm, the disk arm moves into a particular
direction till the end, satisfying all the requests coming in its path, and then it turns backhand
moves in the reverse direction satisfying requests coming in its path.
It works in the way an elevator works, elevator moves in a direction completely till the last floor
of that direction and then turns back.
Strategy to recover IT
Documented plan for Includes roles,
infrastructure and
Disaster Recovery Plan restoring services after responsibilities, and
operations after a
a ransomware attack. recovery steps.
disaster.
Login requires a
Adds additional
Multi-Factor password and an OTP Enhances security
verification layers (e.g.,
Authentication sent to a registered beyond passwords.
OTP, biometric).
mobile.
HTTPS ensures
Encrypt data at rest (on encrypted Protects sensitive
Data Encryption disk) and in transit communication between information from
(during transmission). a browser and a web interception.
server.
3. Computing Environments
Unix/Linux
Aspect Windows Environment Key Point
Environment
File System NTFS: Supports large ext4 (Linux), UFS Unix/Linux file systems
files, journaling, and (Unix): Hierarchical are highly customizable
PowerShell and Command Shells like Bash and Zsh Unix/Linux CLI is more
Command Line
Prompt for scripting and allow automation and powerful for advanced
Interface
administrative tasks. advanced scripting. users and admins.
Unix/Linux allows
Active Directory manages User/group permission detailed access control;
User Management users and permissions model with file-level Windows is easier to
across networks. access control. manage in enterprise
environments.
Unix/Linux is cost-
Often open-source and
Proprietary and requires effective; Windows is
Licensing free (e.g., Ubuntu,
paid licensing. preferred for enterprise
CentOS).
solutions.
Remove an empty
Remove Directory rmdir rmdir
directory
Show network
Network Configuration ipconfig ifconfig
configuration
Check network
Check Network ping ping
connectivity
Check Disk for Errors chkdsk fsck Check the disk for errors