OSY-PT1
OSY-PT1
Types
Hard Real-Time Systems: Strict deadlines must be met.
Soft Real-Time Systems: Deadlines are less strict, with some tolerance for delays.
1. Program Execution
2. I/O Operations
3. File System Manipulation
4. Communication
Program Execution
Description: Manages the loading, execution, and termination of programs.
Functions: Process scheduling, program loading, and process control.
I/O Operations
Description: Manages input and output operations for all devices.
Functions: Device drivers, data buffering, and data transfer coordination.
Explanation:
1. Process Management
2. Memory Management
3. File System Management
4. I/O System Management
5. Device Drivers
Process Management
Description: Manages the creation, scheduling, and termination of processes.
Functions: Process creation, scheduling algorithms, and process control.
Memory Management
Description: Allocates and manages memory resources for processes.
Functions: Memory allocation, paging, and segmentation.
Linked List
Concept: Uses a list of linked blocks to keep track of free memory.
How It Works: Each free block points to the next free block. The last block points to
null.
Advantages: Efficient use of space, easy to allocate and deallocate.
Disadvantages: Slower access compared to bitmap, requires additional memory for
pointers.
Demand Paging
Concept: Only loads parts of a program into RAM when needed.
How It Works: When a program needs a piece of data, it's loaded from disk into RAM.
If RAM is full, some data is swapped out.
Advantages: Saves RAM space, reduces load times.
Disadvantages: May cause delays due to disk access.
Diagram
CPU 1
CPU 2
CPU 3
CPU 4
Q13 Page Replacement Algorithm(LRU)
Page Order: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1
Iteration 1: Page 7
Memory State: [7, -, -]
Explanation: Load page 7. It's the first page, so no need to replace anything.
Page Fault: Yes
Empty Frame
Load Page 7
Memory: 7, -, -
Iteration 2: Page 0
Memory State: [7, 0, -]
Explanation: Load page 0. There's still space available.
Page Fault: Yes
Memory: 7, -, -
Load Page 0
Memory: 7, 0, -
Iteration 3: Page 1
Memory State: [7, 0, 1]
Explanation: Load page 1. The last available slot is filled.
Page Fault: Yes
Memory: 7, 0, -
Load Page 1
Memory: 7, 0, 1
Iteration 4: Page 2
Memory State: [2, 0, 1]
Explanation: Memory is full. Remove the least recently used page (7) and load page
2.
Page Fault: Yes
Memory: 7, 0, 1
Replace 7 with 2
Memory: 2, 0, 1
Iteration 5: Page 0
Memory State: [2, 0, 1]
Explanation: Page 0 is already in memory, so no change.
Page Fault: No
Memory: 2, 0, 1
No Change
Memory: 2, 0, 1
Iteration 6: Page 3
Memory State: [2, 3, 1]
Explanation: Replace the least recently used page (0) with page 3.
Page Fault: Yes
Memory: 2, 0, 1
Replace 0 with 3
Memory: 2, 3, 1
Iteration 7: Page 0
Memory State: [2, 3, 0]
Explanation: Replace the least recently used page (1) with page 0.
Page Fault: Yes
Memory: 2, 3, 1
Replace 1 with 0
Memory: 2, 3, 0
Iteration 8: Page 4
Memory State: [4, 3, 0]
Explanation: Replace the least recently used page (2) with page 4.
Page Fault: Yes
Memory: 2, 3, 0
Replace 2 with 4
Memory: 4, 3, 0
Iteration 9: Page 2
Memory State: [4, 2, 0]
Explanation: Replace the least recently used page (3) with page 2.
Page Fault: Yes
Memory: 4, 3, 0
Replace 3 with 2
Memory: 4, 2, 0
Memory: 4, 2, 0
Replace 0 with 3
Memory: 4, 2, 3
Memory: 4, 2, 3
Replace 4 with 0
Memory: 0, 2, 3
No Change
Memory: 0, 2, 3
Memory: 0, 2, 3
No Change
Memory: 0, 2, 3
Memory: 0, 2, 3
Replace 2 with 1
Memory: 0, 1, 3
Memory: 0, 1, 3
Replace 3 with 2
Memory: 0, 1, 2
Memory: 0, 1, 2
No Change
Memory: 0, 1, 2
No Change
Memory: 0, 1, 2
Memory: 0, 1, 2
Replace 0 with 7
Memory: 7, 1, 2
Memory: 7, 1, 2
Replace 1 with 0
Memory: 7, 0, 2
Memory: 7, 0, 2
Replace 2 with 1
Memory: 7, 0, 1
Explanation Recap
LRU (Least Recently Used) Algorithm: When the memory is full, remove the
page that hasn’t been used for the longest time.
Frame Size: We used a frame size of 3.
Page Faults: A page fault occurs when a page needs to be loaded into memory, but
the memory is full, and a page must be replaced.
Iteration 1: Page 7
Memory State: [7, -, -]
Explanation: Load page 7. It's the first page, so no need to replace anything.
Page Fault: Yes
Empty Frame
Load Page 7
Memory: 7, -, -
Iteration 2: Page 0
Memory State: [7, 0, -]
Explanation: Load page 0. There’s still space available.
Page Fault: Yes
Memory: 7, -, -
Load Page 0
Memory: 7, 0, -
Iteration 3: Page 1
Memory State: [7, 0, 1]
Explanation: Load page 1. The last available slot is filled.
Page Fault: Yes
Memory: 7, 0, -
Load Page 1
Memory: 7, 0, 1
Iteration 4: Page 2
Memory State: [2, 0, 1]
Explanation: Memory is full. Replace the page that will not be used for the longest
time (7).
Page Fault: Yes
Memory: 7, 0, 1
Replace 7 with 2
Memory: 2, 0, 1
Iteration 5: Page 0
Memory State: [2, 0, 1]
Explanation: Page 0 is already in memory, so no change.
Page Fault: No
Memory: 2, 0, 1
No Change
Memory: 2, 0, 1
Iteration 6: Page 3
Memory State: [2, 3, 1]
Explanation: Replace the page that will not be used for the longest time (1).
Page Fault: Yes
Memory: 2, 0, 1
Replace 1 with 3
Memory: 2, 3, 1
Iteration 7: Page 0
Memory State: [2, 3, 0]
Explanation: Replace the page that will not be used for the longest time (2).
Page Fault: Yes
Memory: 2, 3, 1
Replace 2 with 0
Memory: 0, 3, 1
Iteration 8: Page 4
Memory State: [4, 3, 0]
Explanation: Replace the page that will not be used for the longest time (1).
Page Fault: Yes
Memory: 0, 3, 1
Replace 1 with 4
Memory: 4, 3, 0
Iteration 9: Page 2
Memory State: [4, 2, 0]
Explanation: Replace the page that will not be used for the longest time (3).
Page Fault: Yes
Memory: 4, 3, 0
Replace 3 with 2
Memory: 4, 2, 0
Memory: 4, 2, 0
Replace 0 with 3
Memory: 4, 2, 3
Memory: 4, 2, 3
Replace 4 with 0
Memory: 0, 2, 3
No Change
Memory: 0, 2, 3
Memory: 0, 2, 3
No Change
Memory: 0, 2, 3
Memory: 0, 2, 3
Replace 2 with 1
Memory: 0, 1, 3
Memory: 0, 1, 3
Replace 3 with 2
Memory: 0, 1, 2
Memory: 0, 1, 2
No Change
Memory: 0, 1, 2
No Change
Memory: 0, 1, 2
Memory: 0, 1, 2
Replace 0 with 7
Memory: 7, 1, 2
Memory: 7, 1, 2
Replace 1 with 0
Memory: 7, 0, 2
Memory: 7, 0, 2
Replace 2 with 1
Memory: 7, 0, 1
Explanation Recap
Optimal Page Replacement Algorithm: Replaces the page that will not be used
for the longest period in the future.
Frame Size: We used a frame size of 3.
Page Faults: A page fault occurs when a page needs to be loaded into memory, but
the memory is full, and a page must be replaced.