Homework2 Solution
Homework2 Solution
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.
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
‣ 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
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.