0% found this document useful (0 votes)
23 views5 pages

Homework2 Solution

This document outlines Homework 2 for CS4348, due on February 22nd, 2025, which includes questions on processes, threads, and Amdahl's law. Students are required to submit their answers electronically in specific file formats and must provide detailed explanations for various programming and operating system concepts. The homework covers topics such as process states, interrupt handling, execution approaches for operating systems, and the implications of multithreading.

Uploaded by

wobay25311
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views5 pages

Homework2 Solution

This document outlines Homework 2 for CS4348, due on February 22nd, 2025, which includes questions on processes, threads, and Amdahl's law. Students are required to submit their answers electronically in specific file formats and must provide detailed explanations for various programming and operating system concepts. The homework covers topics such as process states, interrupt handling, execution approaches for operating systems, and the implications of multithreading.

Uploaded by

wobay25311
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

cs4348 Homework 2 Spring2025

Homework 2
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.

Due: Sunday, February 22nd 11:59pm

Chapter 3: Processes
1. (10pt) Consider the following sequence of events:
1. Process P0 is created
2. Process P1 is created
3. Process P0, Process P1 are admitted
4. Process P0 is dispatched
5. Process P2 is created
6. Process P2 is admitted
7. Process P0 requests I/O
8. Process P1 is dispatched
9. Process P3 is created
10. Process P1 times-out
11. Process P2 is dispatched
12. Process P3 is admitted
Show how the processes transition through the states of a 5-state model. (At each time point
in the list, what are the states of all processes?)
1. P0 is in New
2. P0,P1 are in New
3. P0, P1 are in Ready
4. P0 is in Running, P1 is in Ready
5. P2 is in New, P0 is in Running, P1 is in Ready
6. P2 is in Ready, P0 is in Running, P1 is in Ready
7. P2 is in Ready, P0 is in Block, P1 is in Ready
8. P2 is in Ready, P0 is in Block, P1 is in Running
9. P2 is in Ready, P0 is in Block, P1 is in Running, P3 is in New
10. P2 is in Ready, P0 is in Block, P1 is in Ready, P3 is in New
11. P2 is in Running, P0 is in Block, P1 is in Ready, P3 is in New

Operating System Concepts Page 1


cs4348 Homework 2 Spring2025

12. P2 is in Running, P0 is in Block, P1 is in Ready, P3 is in Ready


2. (15pt) In a number of early computers, an interrupt caused the register values to be stored in
fixed locations associated with the given interrupt signal. Under what circumstances is this a
practical technique? Explain why it is inconvenient in general. There may be some variation
in the answers. Please make sure that what they answer makes sense. Below are some general
points. Please make sure the students put in more explanation.
It can be practical if the handler just does some task and then returns control to the current
process.
In general, we do not want his behavior. Some interrupts need to be handed over to the OS
for further processing. If we need to return’‘ from an interrupt handler, then we would need
to store it on the stack. In addition, the OS may decide to switch processes. For example, as
with a timer interrupt.
3. (15pt) Compare and contrast the three approaches to executing the OS, according to the book.
Give a scenario for each, where that approach would be the most favorable. Give a scenario
for each, where that approach would be the least favorable. Don’t forget to take into account
the way the computer will be intended to be used.
Here is some information from the book.
• Nonprocess Kernel
‣ traditional approach, common on many older
‣ when the currently running process is interrupted or issues a supervisor call, the mode
context of this process is saved and control is passed to the kernel.
‣ Has its own region of memory to use and its own system stack
‣ Can perform any desired functions and restore the context of the interrupted process
‣ Or complete the function of saving the environment and dispatch another process.
‣ executed as a separate entity that operates in privileged mode
• Kernel within a Process
‣ common with operating systems on smaller computers (PCs, workstations)
‣ execute in the context of a user process.
‣ the OS is a collection of routines the user calls to perform various functions
‣ process image includes a kernel stack
‣ OS code and data are in the shared address space, shared by all user processes
‣ when an interrupt, trap, or supervisor call occurs, the processor is placed in kernel mode
and control is passed to the OS
‣ the mode context is saved and a mode switch takes place
‣ execution continues within the current user process – process switch
‣ If process can continue, the mode is switched again and control goes back to user code.
‣ if a process switch should happen, control is passed to a process-switching routine.
– may take place outside of process

Operating System Concepts Page 2


cs4348 Homework 2 Spring2025

‣ Because of the concept of user mode and kernel mode, protects the operating system
routines
• Process-based OS
‣ OS is a collection of system processes.
‣ software that is part of the kernel executes in a kernel mode.
‣ major kernel functions are separate processes.
‣ encourages the use of a modular OS
‣ some noncritical operating system functions are separate processes.
‣ the function can run at a given priority level and interleaved with other processes
‣ useful in a multiprocessor or multicomputer environment
Each of the above approaches is worth 1 point. Give the point if most of the points made above
are given by the student.
Each scenario is worth 2 points. Give 1 point for giving a scenario and a brief or vague
explanation on why the approach is least or most favorable. Give an additional point if the
explanation is more detailed.
4. (10pt) Consider the following C code.
main ()
{
int pid;
pid = fork ();
printf ("%d \n", pid);
}

There are multiple possible outputs that can result from running this program. Describe what
would be printed for each possible output. Give an explanation of why. There are three possible
types of output.
• Zero followed by some other number greater than zero are printed out on their own lines
• Some number greater than zero and Zero are printed out on their own lines
• −1 followed by a newline
In the first two outputs, fork makes a copy of the current running process, which continues
running concurrently from the same point in the program. The original process has the process
id of the child processes assigned to pid, and the child process has zero assigned. In the third
possible output, the OS was unable to fork the process for some reason, and returns −1, which
is stored in pid.

Chapter 4: Threads
5. (10pt) Explain why, when a ULT blocks for I/O, all ULTs are blocked. Why do KLT not block?
Give examples. The Key points are as follow.
• ULTs are managed by the application

Operating System Concepts Page 3


cs4348 Homework 2 Spring2025

• OS does not know the ULTs exists


• When a ULT blocks for I/O, the OS will block the process.
• Since the process cannot be scheduled, the ULTs cannot run.
Each of the above points are worth 2 points. The final 2 points evaluate the examples.
6. (10pt) If a process exits and there are still threads belonging to that process running, will they
continue to run? Briefly explain why or why not? The Key points are as follow.
• The threads will not continue to run.
• Threads are part of the process.
• When a process exits, it’s resources are freed up. Threads share the processes resources.
Each point above is worth 3 points: 1 point for mentioning the point, 2 points for explaining,
3 points for explaining in detail. Give 1 point answering the question, even if wrong.
7. (15pt) Consider an environment in which there is a one-to-one mapping between user-level
threads and kernel-level threads that allows one or more threads within a process to issue
blocking system calls while other threads continue to run. Explain why this model can make
multithreaded programs run faster than their single-threaded counterparts on a uniprocessor
computer. The multithreaded programs can continue work while waiting for the system calls
to complete. This point is worth 5 points.
The scenario should be explained or diagrammed as part of an explanation of how this makes
it faster. This is worth 5 points.
The student should explain how continuing work while waiting makes the program run faster.
This is worth 5 points.
8. (15pt) Explain Amdahl’s law. Suppose you have a system where only 15% of the code must run
in serial. At what point does increasing the processor result in a trivial difference in speedup
(0.01 or less)?
Amdahl’s law states that we can’t always take full advantage of multiple processors because
some code is inherently serial.
The turning point is at 57 processors.
• 55: 6.043956043956045
• 56: 6.054054054054054, difference of 0.010098010098009702
• 57: 6.063829787234043, difference of 0.009775733179989032
I will also accept somewhere around 47. Which seems about right if you round to two decimal
places.
Amdahl’s law is worth 5 points. Give 2 points for the definition above. An additional point
if the formula is given and explained. An additional 2 points if examples are used to explain
Amdahl’s law.

Operating System Concepts Page 4


cs4348 Homework 2 Spring2025

The remaining 10 points evaluates the “turning point”. There should be at least 3 calculations
as above. The students should show their work. Each calculation is worth 2 points. The
remaining 4 points should evaluate the correctness and any explanation. Give a number of
points based on how well you thing the student demonstrated this is the turning point.

Operating System Concepts Page 5

You might also like