Chapter 1 (OS)
Chapter 1 (OS)
Efficiency: All parts run in one place, making system calls fast.
User Interface: Provides a way for users to interact (e.g., GUI, CLI).
Multi-threaded Multi-processing
Threads share the same memory space. Each process has its own memory space.
Redirection allows sending output to a file or taking input from a file instead of the terminal.
Fd=create(newfile, fmask);
Close(stdin);
dup(fd);
close(fd);
Example:
Fd=create(newfile, fmask);
Close(stdout);
dup(fd);
close(fd);
Example:
ls > filelist.txt
The buffer cache in Unix serves as a temporary storage area for disk blocks to:
Reduce Disk I/O: Frequently accessed data is cached in memory, reducing repetitive disk
reads and writes.
Improve Performance: Accessing data from memory is faster than reading from the disk.
Advantages:
Limitations:
Risk of data loss if dirty buffers are not written back before a crash.
Parse the Path: Split the path into components (e.g., /home/user/file).
Traverse Directories: Start from the root or current directory, navigating each component.
Directory Lookup: For each directory, locate the next component’s inode.
Inode Resolution: Retrieve the inode for the final component.
The buffer pool is a collection of buffers used for caching disk blocks. It includes:
Buffer Headers: Store metadata such as block number, device ID, and status flags.
Device ID: Identifies the disk device associated with the buffer.
Pointers: Link the buffer to the free list or other data structures.
9. What is the Role of the Buffer Cache in Unix? How Does It Improve File System Performance?
Role: The buffer cache temporarily stores disk blocks in memory to speed up data access and reduce
the frequency of disk I/O operations.
Performance Improvements:
Efficient Writes: Combines multiple writes into fewer disk operations, reducing overhead.
◦ Inodes per Block: Each block can hold 1024 / 128 = 8 inodes.
◦ Blocks Required for 32 Files: 32 / 8 = 4 blocks are needed to store the inodes.
Chatgpt Explanation :
Given:
Calculation:
Blocks required: 4
2. In a file system, each inode occupies 128 bytes, and the block size is 2 KB. Calculate the number
of inodes that can be stored in a single block. If a directory contains 100 files, determine how many
blocks are required to store the inodes for these files.
◦ Inodes per Block: Each block can hold 2048 / 128 = 16 inodes.
Given:
Calculation:
Answer:
Blocks required: 7
3. The size of each block on the hard disk is 1 KB, and the size of each inode is 128 bytes. Start
address of Inode block is 3. In which block inode 15 will be found?
Given:
Calculation:
4.A regular le is 25 KB. Analyze how the 13-member array handles this allocation using direct,
single-indirect, and double-indirect pointers. Provide a detailed breakdown of the allocation
process. (Block size = 1 KB)
◦ Single-Indirect Pointer: Points to a block holding 1 KB worth of pointers; it references the remaining
15 - 10 = 5 blocks.
5. If a le is 15 KB in size and the block size is 1 KB, determine how many blocks are allocated to
direct pointers and how many are allocated through single-indirect pointers. Explain your
reasoning.
6. Explain the role of single-indirect pointers when storing a le of 20 KB using a 13- member array
in the inode with a block size of 1 KB. How many blocks are utilized?
7. A file system uses a free block list to allocate disk blocks. Describe how the alloc algorithm
assigns blocks to a new file requiring 5 blocks. If the free block list initially contains [5, 12, 20, 25,
30, 32, 47], show the final state of the free block list after allocation.
◦ Allocation: The algorithm assigns the first 5 blocks: [5, 12, 20, 25, 30].
Given:
o Free block list: [5, 12, 20, 25, 30, 32, 47]
o Required blocks = 5
Allocation Steps:
8. A file is deleted, and the free algorithm is used to reclaim its blocks. The deleted le occupied disk
blocks [10, 11, 15, 20]. If the free block list initially contains [5, 6, 8], demonstrate the state of the
list after the blocks are reclaimed.
Given:
Reclamation:
1. Add the deleted blocks to the free list: [10, 11, 15, 20].
Answer: Final free block list: [5, 6, 8, 10, 11, 15, 20].
9. A file system uses an indexed free block structure. If the free block list has [100, 105, 110, 120,
130], explain how the alloc algorithm assigns blocks to a new file of size 3 KB (block size = 1 KB).
Show the updated free block list.
Given:
o File size = 3 KB
o Block size = 1 KB
Allocation Steps:
c.Discuss how separating output and error logs can streamline system monitoring.
1. Standard Input (stdin): Accepts input from the user or another program (default is the
keyboard).
2. Standard Output (stdout): Outputs normal operation results (default is the terminal).
Commands:
c. Discuss: Separating outputs and errors improves clarity and allows monitoring each aspect
independently without overwriting crucial data.
2.Describe the role of standard input, output, and error streams in Unix. Write a series of commands
to:
wc < data.txt
d. Benefit of appending errors: Ensures that past errors are not lost and facilitates tracking issues
over time.
3.Explain the three standard input/output (I/O) streams in Unix systems. Briefly describe the purpose
of each stream. Write a command to:
3. Explain how this redirection can simplify troubleshooting a script searching for patterns in
multiple files.
Commands:
c. Explanation: Combining output and errors in one file helps pinpoint issues during
pattern searching, especially across multiple files.
4.Differentiate between hardware interrupts and software exceptions with examples of how each is
triggered in a system.
Hardware Interrupts: Triggered by hardware devices (e.g., a keyboard press, disk I/O).
5.Discuss the concept of interruptions and their types maskable and non-maskable interrupts and
high-priority and low-priority interrupts. Provide an example of each type Explain how they differ in
their handling by the processor
Low-Priority Interrupts: Handled when higher-priority interrupts are not pending (e.g., periodic
timer).
6.Analyze the concept of processor execution level in handling interrupts. Comment on the following
scenarios:
o Discuss the potential effects on interrupt servicing and overall system performance.
o Analyze the behavior of the system when the processor is at a low execution level
during interrupt handling.
o Discuss how interrupts are prioritized and the possible delays in handling higher-
priority interrupts.
o What impact could this have on real-time system requirements and interrupt
latency?
System prioritizes all interrupts but may delay critical high-priority tasks, causing latency in
real-time systems.
7.Pipelines allow for chaining commands to perform complex tasks efficiently. Construct a pipeline
to:
Explanation:
Justify the use of each command in the pipeline and explain how the pipeline achieves the
task.
Explanation:
find /var/log -type f -mtime -7: Finds files modified in the last 7 days.
Explanation:
10.Discuss the advantages of using a pipeline for this task and the functionality of each command.
Streamlined command chaining avoids intermediate files.