homework6KT
homework6KT
Kabir Tapiawala
CS 4348.502
Dr. Salazar
12/5/2024
Homework 6
Answer the questions below, and submit electronically via elearning. Make sure you
submit a couple hours early at the latest and double check your submission to ensure
everything is in order before the submission time. Your answers should be submitted as
a “.doc”, “.docx”, or “.pdf” file. Your answers should be typed, but scans or pictures of
hand drawn figures and diagrams may be included in the file when needed. For
questions where you must write code, turn in the source code files along with your Word
or pdf file.
One example of a system-oriented criterion that isn’t directly mentioned in the notes is
CPU Utilization.
CPU Utilization evaluates how much of the CPU’s capacity is actively being used for
processing tasks. A higher utilization generally signifies that the system is making good
use of its processing power, reducing downtime, and boosting throughput. This metric is
vital for gauging whether system resources are being efficiently used, which contributes
to smoother performance and optimized operation.
Briefly explain. 4. (10pt) For the following processes, perform round-robin scheduling.
0 0 16
1 3 16
2 5 14
3 5 10
4 6 4
You use the format we used in class. Assume the processes do not perform I/O. Use
5 as the time quantum.
Timeline:
At time 0:
Process 0 arrives.
Dispatch Process 0.
At time 3:
Process 1 arrives.
At time 5:
Process 0 times out (used 5 units; remaining 11 units).
Processes 2 and 3 arrive.
Ready queue is now [P1, P2, P3, P0].
Dispatch Process 1.
At time 6:
Process 4 arrives.
Ready queue is [P2, P3, P0, P4] after adding P4 behind P0.
At time 10:
Process 1 times out (used 5 units; remaining 11 units).
Ready queue: [P2, P3, P0, P4, P1].
Dispatch Process 2.
At time 15:
Process 2 times out (used 5 units; remaining 9 units).
Ready queue: [P3, P0, P4, P1, P2].
Dispatch Process 3.
At time 20:
Process 3 times out (used 5 units; remaining 5 units).
Ready queue: [P0, P4, P1, P2, P3].
Dispatch Process 0.
At time 25:
Process 0 times out (used 5 units; remaining 6 units).
Ready queue: [P4, P1, P2, P3, P0].
Dispatch Process 4.
At time 29:
Process 4 completes execution (used 4 units; remaining 0 units).
Remove P4 from the system.
Ready queue: [P1, P2, P3, P0].
Dispatch Process 1.
At time 34:
Process 1 times out (used 5 units; remaining 6 units).
Ready queue: [P2, P3, P0, P1].
Dispatch Process 2.
At time 39:
Process 2 times out (used 5 units; remaining 4 units).
Ready queue: [P3, P0, P1, P2].
Dispatch Process 3.
At time 44:
Process 3 completes execution (used 5 units; remaining 0 units).
Remove P3.
Ready queue: [P0, P1, P2].
Dispatch Process 0.
At time 49:
Process 0 times out (used 5 units; remaining 1 unit).
Ready queue: [P1, P2, P0].
Dispatch Process 1.
At time 54:
Process 1 times out (used 5 units; remaining 1 unit).
Ready queue: [P2, P0, P1].
Dispatch Process 2.
At time 58:
Process 2 completes execution (used 4 units; remaining 0 units).
Remove P2.
Ready queue: [P0, P1].
Dispatch Process 0.
At time 59:
Process 0 completes execution (used 1 unit; remaining 0 units).
Remove P0.
Ready queue: [P1].
Dispatch Process 1.
At time 60:
Process 1 completes execution (used 1 unit; remaining 0 units).
All processes have completed execution.
● Operating System Concepts Page 1
0 0 16
1 3 16
2 5 14
3 5 10
4 6 4
5 8 14
6 9 3
7 10 18
You use the format we used in class. Assume the processes do not perform I/O.
1. At time 0:
○ Process 0 arrives.
○ CPU is idle; dispatch Process 0.
○ Process 0 starts running.
2. At time 3:
○ Process 1 arrives.
○ Process 0 continues running (Remaining Time: 16 - (3 - 0) = 13 units).
○ Process 1 has Remaining Time: 16 units.
○ No preemption occurs.
3. At time 5:
○ Process 2 and Process 3 arrive.
○ Process 0 has Remaining Time: 16 - (5 - 0) = 11 units.
○ Process 3 has Remaining Time: 10 units.
○ Process 3 preempts Process 0.
○ At time 5, dispatch Process 3.
○ Process 3 starts running.
4. At time 6:
○ Process 4 arrives.
○ Process 3 has Remaining Time: 10 - (6 - 5) = 9 units.
○ Process 4 has Remaining Time: 4 units.
○ Process 4 preempts Process 3.
○ At time 6, dispatch Process 4.
○ Process 4 starts running.
5. At time 8:
○ Process 5 arrives.
○ Process 4 has Remaining Time: 4 - (8 - 6) = 2 units.
○ Process 4 continues running.
○ No preemption occurs.
6. At time 9:
○ Process 6 arrives.
○ Process 4 has Remaining Time: 4 - (9 - 6) = 1 unit.
○ Process 4 continues running.
○ No preemption occurs.
7. At time 10:
○ Process 7 arrives.
○ Process 4 completes execution.
○ Process 4 exits.
○ Available Processes:
■ Process 0 (Remaining Time: 11 units)
■ Process 1 (Remaining Time: 16 units)
■ Process 2 (Remaining Time: 14 units)
■ Process 3 (Remaining Time: 9 units)
■ Process 5 (Remaining Time: 14 units)
■ Process 6 (Remaining Time: 3 units)
■ Process 7 (Remaining Time: 18 units)
○ Process 6 has the shortest remaining time.
○ Dispatch Process 6.
○ Process 6 starts running.
8. At time 13:
○ Process 6 completes execution.
○ Process 6 exits.
○ Available Processes:
■ Process 0 (Remaining Time: 11 units)
■ Process 1 (Remaining Time: 16 units)
■ Process 2 (Remaining Time: 14 units)
■ Process 3 (Remaining Time: 9 units)
■ Process 5 (Remaining Time: 14 units)
■ Process 7 (Remaining Time: 18 units)
○ Process 3 has the shortest remaining time.
○ Dispatch Process 3.
○ Process 3 resumes running.
9. At time 22:
○ Process 3 completes execution.
○ Process 3 exits.
○ Available Processes:
■ Process 0 (Remaining Time: 11 units)
■ Process 1 (Remaining Time: 16 units)
■ Process 2 (Remaining Time: 14 units)
■ Process 5 (Remaining Time: 14 units)
■ Process 7 (Remaining Time: 18 units)
○ Process 0 has the shortest remaining time.
○ Dispatch Process 0.
○ Process 0 resumes running.
10. At time 33:
○ Process 0 completes execution.
○ Process 0 exits.
○ Available Processes:
■ Process 1 (Remaining Time: 16 units)
■ Process 2 (Remaining Time: 14 units)
■ Process 5 (Remaining Time: 14 units)
■ Process 7 (Remaining Time: 18 units)
○ Process 2 and Process 5 have equal remaining times.
○ Process 2 arrived earlier.
○ Dispatch Process 2.
○ Process 2 starts running.
11. At time 47:
○ Process 2 completes execution.
○ Process 2 exits.
○ Available Processes:
■ Process 1 (Remaining Time: 16 units)
■ Process 5 (Remaining Time: 14 units)
■ Process 7 (Remaining Time: 18 units)
○ Process 5 has the shortest remaining time.
○ Dispatch Process 5.
○ Process 5 starts running.
12. At time 61:
○ Process 5 completes execution.
○ Process 5 exits.
○ Available Processes:
■ Process 1 (Remaining Time: 16 units)
■ Process 7 (Remaining Time: 18 units)
○ Process 1 has the shortest remaining time.
○ Dispatch Process 1.
○ Process 1 starts running.
13. At time 77:
○ Process 1 completes execution.
○ Process 1 exits.
○ Available Process:
■ Process 7 (Remaining Time: 18 units)
○ Dispatch Process 7.
○ Process 7 starts running.
14. At time 95:
○ Process 7 completes execution.
○ Process 7 exits.
○ All processes have completed execution.
6. (2pt) How does virtual round robin differ from round robin? What would be the
purpose of using virtual round robin of round robin?
● Round Robin (RR): This scheduling method assigns each process a fixed time
slice (quantum) in a cyclic order. It ensures that all processes receive an equal
share of CPU time, promoting simplicity and fairness.
● Virtual Round Robin (VRR): An enhanced version of RR, VRR incorporates
virtual time or adjusts process priorities dynamically. This makes CPU allocation
more flexible and tailored to process characteristics or system needs.
1. Improved Efficiency:
VRR adapts to process demands and priorities, resulting in better CPU usage. It
also minimizes delays for interactive or higher-priority tasks compared to the
fixed, cyclic approach of RR.
2. Enhanced Fairness:
By dynamically adjusting priorities, VRR ensures that critical processes are
addressed promptly, reducing the chance of delays caused by the rigid
time-slicing of traditional RR.
7. (4pt) Briefly describe exponential averaging. What is its purpose? What scheduling
algorithms might use it?
Exponential Averaging
Definition:
Exponential averaging is a prediction method that assigns more weight to recent
observations while still factoring in past data. It calculates a weighted average, where
the influence of older data points diminishes exponentially. This approach allows
systems to adapt quickly to recent changes.
Purpose
The main purpose of exponential averaging is to provide timely and accurate estimates
for process metrics, such as CPU burst times. By focusing on recent behavior, it enables
schedulers to make decisions that better reflect the current state of processes,
improving overall efficiency and performance.
Formula:
Work:
1. CPUj(i-1) = 10
2. CPUj(i) = 10 / 2 = 5
3. Effective CPU usage for priority = 5 / 2 = 2.5
4. GCPUk(i-1) = 10
5. GCPUk(i) = 10 / 2 = 5
6. Substitute: Pj(i) = 5 + 2.5 + (5 / (4 * 0.5))
7. Simplify: Pj(i) = 5 + 2.5 + 2.5 = 7.5
Final Answer:
7.5
9. (2pt) What is the difference between hard and soft real-time tasks?
● Definition: Must meet deadlines strictly; missing them can cause catastrophic
outcomes.
● Example: Car brakes—failing to activate in time can result in collisions.
● Key Point: Deadlines are mandatory and critical.
● Definition: Prefer to meet deadlines but can tolerate occasional misses with
minor consequences.
● Example: Real-time clock—delayed updates may cause jitter but remain
functional.
● Key Point: Deadlines are flexible and non-critical.
10. (4pt) Briefly define the five general areas of requirements for a real-time operating
system.
1. Determinism (Predictability):
○ Definition: The ability of the system to perform operations at fixed,
predetermined times or intervals.
○ Explanation: RTOS must exhibit predictable behavior, ensuring that tasks
are executed within specified time constraints. While complete
predictability is unattainable due to unpredictable inputs, minimizing
variability in task execution times is crucial.
2. Responsiveness:
○ Definition: The speed at which the operating system responds to events,
such as interrupts.
○ Explanation: An RTOS must quickly acknowledge and service interrupts
to meet task deadlines. This involves having minimal and guaranteed
maximum delays between event detection and interrupt handling.
3. User Control:
○ Definition: Fine-grained control over system operations and resource
management.
○ Explanation: Users require precise control over system functions, such as
memory management and paging. This allows users to prevent operations
that could interfere with meeting deadlines, like controlling when pages are
flushed to memory.
4. Reliability:
○ Definition: High system reliability to ensure consistent operation without
failures.
○ Explanation: RTOS must be highly reliable because failures can lead to
catastrophic consequences, including physical damage or loss of life.
Systems like auto-braking in cars rely on this reliability to function correctly.
5. Fail Soft Operations (Fault Tolerance):
○ Definition: The ability of the system to continue operating and handling
critical tasks even in the presence of errors.
○ Explanation: RTOS should maintain essential functions despite partial
system failures. For example, if a non-critical component fails, the system
should still manage critical operations like decision-making in real time.
11. (4pt) Briefly define the four classes of real-time scheduling algorithms.
Explanation:
Using a single ready queue ensures workloads are evenly distributed among all
processors. When a processor becomes idle, it quickly retrieves the next thread,
avoiding bottlenecks and preventing underutilization of other processors. This approach
maximizes processor usage and improves system efficiency.
14. (10pt) For the following processes, perform Dedicated Processor Assignment.
PID Number of Admit Time Service Time
Threads
0 4 0 8
1 4 3 11
2 3 4 16
3 2 4 18
4 4 6 4
The service time is for the entire process. It is assumed that all thread exist during
this time. You use the format we used in class for the chapter 9 examples. Assume
the system has 6 processors. Assume any I/O is part of the service time. Processes
that cannot be assigned enough processors cannot be dispatched.
Scheduling Steps:
1. Time 0:
○ Process 0 arrives.
○ Requires 4 processors (since it has 4 threads).
○ Available processors: 6.
○ Action: Assign 4 processors to Process 0.
○ Remaining processors: 2.
2. Time 3:
○ Process 1 arrives.
○ Requires 4 processors.
○ Available processors: 2 (since Process 0 is using 4 processors).
○ Action: Cannot dispatch Process 1 (not enough processors available).
○ Process 1 waits.
3. Time 4:
○ Process 2 and Process 3 arrive.
○ Process 2 requires 3 processors.
○ Process 3 requires 2 processors.
○ Available processors: 2.
○ Action:
■ Cannot dispatch Process 2 (requires 3 processors).
■ Dispatch Process 3 (requires 2 processors).
○ Assign 2 processors to Process 3.
○ Remaining processors: 0.
4. Time 6:
○ Process 4 arrives.
○ Requires 4 processors.
○ Available processors: 0.
○ Action: Cannot dispatch Process 4 (no available processors).
○ Process 4 waits.
5. Time 8:
○ Process 0 completes (service time of 8 units).
○ Releases 4 processors.
○ Available processors: 4.
○ Waiting Processes: Process 1, Process 2, Process 4.
○ Priority (based on arrival time):
■ Process 1 (arrived at time 3)
■ Process 2 (arrived at time 4)
■ Process 4 (arrived at time 6)
○ Action:
■ Dispatch Process 1 (requires 4 processors).
■ Assign 4 processors to Process 1.
○ Remaining processors: 0.
6. Time 19:
○ Process 1 completes (service time of 11 units from time 8 to 19).
○ Releases 4 processors.
○ Available processors: 4.
○ Waiting Processes: Process 2, Process 4.
○ Action:
■ Dispatch Process 2 (requires 3 processors).
■ Assign 3 processors to Process 2.
○ Remaining processors: 1.
7. Time 22:
○ Process 3 completes (service time of 18 units from time 4 to 22).
○ Releases 2 processors.
○ Available processors: 3 (1 + 2).
○ Waiting Processes: Process 4.
○ Action:
■ Process 4 requires 4 processors; only 3 are available.
■ Cannot dispatch Process 4.
○ Remaining processors: 3.
8. Time 35:
○ Process 2 completes (service time of 16 units from time 19 to 35).
○ Releases 3 processors.
○ Available processors: 6 (3 + 3).
○ Waiting Processes: Process 4.
○ Action:
■ Dispatch Process 4 (requires 4 processors).
■ Assign 4 processors to Process 4.
○ Remaining processors: 2.
9. Time 39:
○ Process 4 completes (service time of 4 units from time 35 to 39).
○ Releases 4 processors.
○ Available processors: 6.
○ All processes have completed execution.
15. (10pt) For the following processes and threads, perform the dynamic scheduling
algorithm based on ZAHO90.
PID TID Spawn Time Service Time
0 0 2 4
0 1 6 3
1 0 2 9
1 1 9 4
1 2 9 1
2 0 1 10
2 1 2 4
2 2 5 4
2 3 9 10
3 0 4 6
3 1 10 9
4 0 2 10
4165
You may use the format we used in class for the chapter 9 examples. You can have
a “ready queue” for each process to hold ready threads that do not have a
processor. Assume the system has 6 processors. Assume any I/O is part of the
service time. Whenever a thread is spawned, the process will request a processor
for it. When a thread exits, the processor is released. To keep things simple, we will
assume the threads are independent of each other. So, no thread will block to wait
for another thread.
Scheduling Steps:
1. Time 1:
○ Threads Spawned:
■ Process 1, Thread 1 (P1 T1): Spawn Time 9, Service Time 4.
■ Process 3, Thread 0 (P3 T0): Spawn Time 1, Service Time 9.
○ Processors Available: 6.
○ Process Requests:
■ Process 3 requests 1 processor.
○ Actions:
■ Allocate 1 processor to Process 3.
○ Processors Remaining: 5.
○ Process Allocations:
■ Process 3: 1 processor.
2. Time 2:
○ Threads Spawned:
■ Process 0, Thread 0 (P0 T0): Spawn Time 2, Service Time 4.
■ Process 2, Thread 1 (P2 T1): Spawn Time 2, Service Time 4.
■ Process 0, Thread 6 (P0 T6): Spawn Time 2, Service Time 3.
■ Process 4, Thread 10 (P4 T10): Spawn Time 2, Service Time 10.
○ Process Requests:
■ Process 0 requests 1 processor.
■ Process 2 requests 1 processor.
■ Process 0 requests 1 additional processor.
■ Process 4 requests 1 processor.
○ Processors Available: 5.
○ Actions:
■ Allocate 1 processor to Process 0 (P0 T0).
■ Allocate 1 processor to Process 2 (P2 T1).
■ Allocate 1 processor to Process 0 (P0 T6).
■ Allocate 1 processor to Process 4 (P4 T10).
○ Processors Remaining: 1.
○ Process Allocations:
■ Process 0: 2 processors.
■ Process 2: 1 processor.
■ Process 4: 1 processor.
■ Process 3: 1 processor.
3. Time 3:
○ Threads Spawned:
■ Process 2, Thread 3 (P2 T3): Spawn Time 3, Service Time 4.
○ Process Request:
■ Process 2 requests 1 additional processor.
○ Processors Available: 1.
○ Actions:
■ Allocate 1 processor to Process 2 (now has 2 processors).
○ Processors Remaining: 0.
○ Process Allocations:
■ Process 2: 2 processors.
4. Time 5:
○ Threads Spawned:
■ Process 2, Thread 2 (P2 T2): Spawn Time 5, Service Time 4.
○ Process Request:
■ Process 2 requests 1 additional processor (total requested: 3).
○ Processors Available: 0.
○ Actions:
■ Process 2 cannot be allocated the additional processor.
■ Process 2 is not a new arrival.
■ Request remains outstanding.
○ Outstanding Requests:
■ Process 2 requests 1 processor.
5. Time 6:
○ Threads Completed:
■ Process 0, Thread 0 (P0 T0): Service Time 4 units (Started at Time
2, Completed at Time 6).
■ Process 2, Thread 1 (P2 T1): Service Time 4 units (Started at Time
2, Completed at Time 6).
○ Processors Released: 1 from Process 0, 1 from Process 2.
○ Processors Available: 2.
○ Threads Spawned:
■ Process 4, Thread 1 (P4 T1): Spawn Time 6, Service Time 5.
○ Process Requests:
■ Process 4 requests 1 processor.
○ Actions:
■ Process 4 is a new arrival.
■ Allocate 1 processor to Process 4.
■ Process 2 has an outstanding request.
■ Allocate 1 processor to Process 2 (now has 2 processors).
○ Processors Remaining: 0.
○ Process Allocations:
■ Process 0: 1 processor.
■ Process 2: 2 processors.
■ Process 3: 1 processor.
■ Process 4: 1 processor.
6. Time 7:
○ Threads Completed:
■ Process 0, Thread 6 (P0 T6): Service Time 3 units (Started at Time
2, Completed at Time 5).
■ Process 2, Thread 3 (P2 T3): Service Time 4 units (Started at Time
3, Completed at Time 7).
○ Processors Released: 1 from Process 2.
○ Processors Available: 1.
○ Actions:
■ No outstanding requests.
■ Processor remains idle.
○ Process Allocations:
■ Process 0: 1 processor.
■ Process 2: 1 processor.
■ Process 3: 1 processor.
■ Process 4: 1 processor.
7. Time 9:
○ Threads Spawned:
■ Process 1, Thread 1 (P1 T1): Spawn Time 9, Service Time 4.
○ Process Request:
■ Process 1 requests 1 processor.
○ Processors Available: 1.
○ Actions:
■ Allocate 1 processor to Process 1 (now has 2 processors).
○ Processors Remaining: 0.
○ Process Allocations:
■ Process 1: 2 processors.
8. Time 10:
○ Threads Completed:
■ Process 3, Thread 0 (P3 T0): Service Time 9 units (Started at Time
1, Completed at Time 10).
○ Processors Released: 1 from Process 3.
○ Processors Available: 1.
○ Actions:
■ No outstanding requests.
■ Processor remains idle.
○ Process Allocations:
■ Process 3: 0 processors.
9. Time 11:
○ Threads Completed:
■ Process 1, Thread 2 (P1 T2): Service Time 9 units (Started at Time
0, Completed at Time 11).
■ Process 4, Thread 1 (P4 T1): Service Time 5 units (Started at Time
6, Completed at Time 11).
■ Process 2, Thread 2 (P2 T2): Service Time 4 units (Started at Time
5, Completed at Time 9).
○ Processors Released: 1 from Process 1, 1 from Process 4, 1 from
Process 2.
○ Processors Available: 3.
○ Actions:
■ No outstanding requests.
■ Processors remain idle.
○ Process Allocations:
■ Process 1: 1 processor.
■ Process 2: 1 processor.
10. Time 13:
○ Threads Completed:
■ Process 1, Thread 1 (P1 T1): Service Time 4 units (Started at Time
9, Completed at Time 13).
○ Processors Released: 1 from Process 1.
○ Processors Available: 4.
○ Actions:
■ No outstanding requests.
■ Processors remain idle.
○ Process Allocations:
■ Process 1: 0 processors.
11. Time 13 Onwards:
○ All threads have completed.
○ All processors are available.
16. (2pt) How does Dedicated Processor Assignment differ from Gang Scheduling?
Dedicated Processor Assignment
Gang Scheduling
Key Differences:
1. Processor Allocation:
○ Dedicated: Fixed processors assigned for the process duration.
○ Gang: Dynamically assigns processors, sharing resources as needed.
2. Flexibility:
○ Dedicated: Less flexible—processors are locked to one process.
○ Gang: More flexible—processors can be shared across different gangs.
3. Overhead:
○ Dedicated: Low overhead—no context switching.
○ Gang: Reduces thread sync delays but requires dynamic processor
management.
Multiprocessor Scheduling:
Key Differences:
1. Hardware Structure:
○ Multicore: Focuses on cores within one processor.
○ Multiprocessor: Involves multiple physical processors.
2. Resource Sharing:
○ Multicore: Cores share caches and buses.
○ Multiprocessor: Processors often have dedicated resources.
3. Complexity:
○ Multicore: Requires fine-grained scheduling to handle shared resources.
○ Multiprocessor: Needs higher-level coordination for independent
processors.
18. (4pt) Briefly describe Type 1 and Type 2 virtualization. What are their advantages
and disadvantages?
Type 1 Virtualization (Bare-Metal Hypervisor):
19. (8pt) Describe paravirtualization. How does it increase the speed of virtual
machines?
Definition:
Advantages
Disadvantages
1. Guest OS Modifications: Requires altering the OS, which may not always be
feasible.
2. Compatibility Issues: Not all operating systems support paravirtualization.
3. Complex Setup: Involves integrating specialized drivers, adding implementation
challenges.
20. (8pt) Compare and contrast container virtualization with virtual machines.
Key Point: VMs provide stronger isolation, while containers are more lightweight and
share the host OS kernel.
Key Point: Containers are faster and use fewer resources, while VMs have higher
overhead due to emulation.
● VMs: Allow running different operating systems on the same hardware, offering
greater flexibility.
● Containers: Are highly portable but limited to the host OS kernel.
Key Point: VMs offer more flexibility in running varied OSes, whereas containers excel
in portability for compatible environments.
4. Security Considerations
Key Point: VMs are more secure due to complete isolation, while containers require
careful configuration to mitigate risks.
5. Use Cases
● VMs: Ideal for running multiple OSes, enterprise environments, and scenarios
needing strict isolation.
● Containers: Best for development, testing, microservices, and rapid scaling.
Key Point: VMs suit tasks needing strong isolation, while containers shine in
lightweight, agile deployments.
Definition:
Ballooning is a memory management technique in virtualized environments that
dynamically adjusts memory allocation for virtual machines (VMs) based on their needs
and the host's memory availability.
How It Works:
Purpose:
Ballooning ensures efficient memory usage by redistributing resources dynamically,
preventing memory shortages and allowing the system to support more VMs.
Operating System Concepts Page 4