Os 2019
Os 2019
Tushar Ahuja
Tushar Ahuja
Causes of Thrashing:
1. Overcommitment of Memory: When too many processes
are running, and their combined memory demands exceed
the physical RAM, the system starts swapping pages in
and out frequently.
2. Insufficient RAM: Not enough physical memory to handle
the running processes.
3. High Degree of Multiprogramming: Running too many
processes simultaneously can lead to excessive context
switching and paging.
Symptoms of Thrashing:
• The system becomes extremely slow.
• High disk activity (ex: hard drive or SSD is constantly on).
• Low CPU utilization despite a heavy load of processes.
Example:
Suppose a system has 4GB of RAM and is running multiple
applications. If these applications require 6GB of memory, the
OS will use 2GB of virtual memory from the disk. If the working
set of active processes keeps changing, pages are frequently
swapped in and out, leading to thrashing.
(B)
Tushar Ahuja
Tushar Ahuja
Tushar Ahuja
1. External Fragmentation
• Definition: Occurs when free memory is scattered
throughout the system, but none of the free blocks is large
enough to satisfy a request.
• Cause: Arises due to continuous memory allocation when
small gaps of unusable memory are left between allocated
blocks.
• Example: If 100 MB of memory is free but split into two
blocks of 60 MB and 40 MB, a process requiring 70 MB
cannot be allocated memory.
Solution:
• Compaction: Rearranges memory to consolidate free
spaces into a single large block.
• Use Non-Continuous Memory Allocation: Techniques
like paging or segmentation reduce external
fragmentation.
Tushar Ahuja
2. Internal Fragmentation
• Definition: Occurs when the allocated memory block is
larger than the memory required by a process, leaving
unused space inside the block.
• Cause: Arises due to fixed-sized memory partitions or
page sizes, where the size of the memory allocated to a
process does not exactly match its requirement.
• Example: If a process requires 28 KB but is allocated a 32
KB block, the remaining 4 KB is wasted.
Solution:
• Dynamic Partitioning: Allocate exactly the amount of
memory needed for a process.
• Use Smaller Page Sizes: Reducing page size can help
minimize wasted space.
2. Dynamic Partitioning
• Description: Memory is divided into partitions of variable
sizes based on the process requirements.
Tushar Ahuja
3. Paging
• Description: Divides memory into fixed-size blocks called
pages. Processes are divided into pages and mapped to
frames in memory.
• Advantage: Eliminates external fragmentation.
• Disadvantage: May cause internal fragmentation if page
sizes are large.
4. Segmentation
• Description: Divides a process into segments based on
logical divisions (e.g., code, data, stack). Each segment is
stored in a different part of memory.
• Advantage: Provides logical division and more efficient
memory use.
• Disadvantage: Can lead to external fragmentation.
(B)
Tushar Ahuja
Tushar Ahuja
Tushar Ahuja
Tushar Ahuja
Tushar Ahuja
3. Medium-Term Scheduler
It is responsible for
suspending and resuming
process. It mainly
does swapping (moving
processes from main
memory to disk and vice
versa). Swapping may be
necessary to improve the
process mix or because a
change in memory requirements has overcommitted available
memory, requiring memory to be freed up. It is helpful in
maintaining a perfect balance between the I/O bound and the
CPU bound. It reduces the degree of multiprogramming.
Tushar Ahuja
Semaphore Initialization
• mutex = 1: Ensures only one process accesses the buffer
at a time.
• empty = n: Represents the number of empty slots in the
buffer (initially all slots are empty).
• full = 0: Represents the number of filled slots in the buffer
(initially none).
Tushar Ahuja
Pseudocode
Producer Process
Consumer Process
Tushar Ahuja
Tushar Ahuja
3. No Preemption
• Resources cannot be forcibly taken away from a process.
They can only be released voluntarily by the process
holding them, after the process has completed its task.
Example:
• If a process is holding a resource, the OS cannot force the
process to release it; it must wait until the process is done.
4. Circular Wait
• A set of processes is waiting in a circular chain, where
each process is waiting for a resource that the next
process in the chain holds.
Example:
• Process A waits for Resource B.
• Process B waits for Resource C.
• Process C waits for Resource A.
Tushar Ahuja
Deadlock Prevention
This method ensures that at least one of the necessary
conditions for deadlock cannot occur. The four conditions for
deadlock are:
1. Mutual Exclusion
o Resources cannot be shared simultaneously.
2. Hold and Wait
o Processes hold allocated resources while waiting for
additional ones.
3. No Preemption
o Resources cannot be forcibly taken away from
processes.
4. Circular Wait
o A circular chain of processes exists, where each
process waits for a resource held by the next.
Approach:
• Mutual Exclusion: Allow sharing of some resources
wherever possible (e.g., read-only files).
Tushar Ahuja
(B)
Tushar Ahuja
Tushar Ahuja
Tushar Ahuja
ANS. (A)
• Application Programs: This is
the topmost layer where users
interact with files through
applications. It provides the user
interface for file operations like
creating, deleting, reading,
writing, and modifying files.
Examples include text editors, file
browsers, & command-line
interfaces.
• Logical File system – It
manages metadata information
about a file i.e includes all details
about a file except the actual
contents of the file. It also
maintains via file control blocks. File control block (FCB)
has information about a file – owner, size, permissions,
and location of file contents.
• File Organization Module – It has information about files,
the location of files and their logical and physical blocks.
Physical blocks do not match with logical numbers of
logical blocks numbered from 0 to N. It also has a free
space that tracks unallocated blocks.
• Basic File system – It Issues general commands to the
device driver to read and write physical blocks on disk. It
manages the memory buffers and caches. A block in the
buffer can hold the contents of the disk block and the
cache stores frequently used file system metadata.
Tushar Ahuja
Program Threats
Program threats are vulnerabilities or malicious activities
targeting software or applications. These often exploit
weaknesses in application design, code, or logic.
Examples of Program Threats
1. Trojan Horses
o Malicious programs disguised as legitimate software.
o Example: A fake antivirus program that actually
installs malware.
2. Logic Bombs
o Malicious code that triggers harmful actions when
specific conditions are met.
Tushar Ahuja
System Threats
System threats target the hardware, operating system, or
underlying infrastructure, potentially compromising the entire
system. These often focus on resource manipulation,
unauthorized access, or system failure.
Tushar Ahuja
1. Contiguous Allocation
In contiguous allocation, each file is stored in a contiguous
set of disk blocks.
How It Works:
• The file is allocated a sequence of consecutive blocks on
the disk.
• The starting block and the length of the file (number of
blocks) are stored in the directory.
Advantages:
• Fast Access: Sequential and random access are quick
due to contiguous storage.
• Simplicity: Easy to implement and manage.
Disadvantages:
• External Fragmentation: Free space is scattered, making
it hard to find contiguous blocks.
• Difficulty in File Growth: If a file grows beyond its
allocated space, relocation or defragmentation is needed.
2. Linked Allocation
In linked allocation, each file is a linked list of disk blocks,
which may be scattered anywhere on the disk.
How It Works:
• Each block contains a pointer to the next block of the file.
• The directory stores the starting block and size of the file.
Advantages:
• No External Fragmentation: Blocks can be scattered
across the disk.
Tushar Ahuja
3. Indexed Allocation
In indexed allocation, an index block is used to keep pointers
to all the blocks of a file.
How It Works:
• Each file has an index block containing pointers to its data
blocks.
• The directory stores the address of the index block.
Advantages:
• No External Fragmentation: Blocks can be scattered.
• Fast Random Access: Direct access to any block via the
index block.
Disadvantages:
• Overhead of Index Block: Additional disk space is
required for the index.
• Size Limitation: The number of blocks a file can have is
limited by the size of the index block.
Tushar Ahuja
1. Sequential Access
Description:
• Data is accessed in a specific order, from the beginning of
the file to the end, one record at a time.
• It is the simplest and most common access method.
Operations:
• Read Next: Reads the next block of data.
• Write Next: Appends data at the end of the file.
Advantages:
• Simple to implement.
Tushar Ahuja
Description:
• Data blocks can be accessed directly without reading
through other blocks.
• Each block has a unique address, and access is based on
this address.
Operations:
Tushar Ahuja
3. Indexed Access
Description:
• Uses an index to keep track of where data blocks are
located. The index maps logical data positions to physical
storage locations.
How It Works:
• A separate index file is maintained.
• The index points to data blocks, enabling efficient access.
Advantages:
• Fast access to specific data.
• Efficient for files with a large number of records.
Disadvantages:
• Overhead of maintaining the index.
• Extra storage space is required for the index.
Tushar Ahuja
Use Cases:
• Large databases, file systems with frequent random
access needs.
5. Clustered Access
Description:
• Data that is frequently accessed together is stored in
clusters for efficiency.
Tushar Ahuja
Advantages:
• Reduces disk seek time.
• Improves access time for related data.
Disadvantages:
• Data clustering might require complex data management.
• Potential overhead in rearranging data as usage patterns
change.
Use Cases:
• Relational databases with joined tables.