Homework 2 answers

docx

School

Georgia State University *

*We aren’t endorsed by this school

Course

4320

Subject

Computer Science

Date

Apr 3, 2024

Type

docx

Pages

4

Uploaded by heebamerchant

Report
Operating Systems Homework 2 Heeba Merchant 1. Interruptions: Correctly arrange the following steps to handle an interruption of a running user process by assigning them the correct step number from 1 to 9 (9 points): Step Step number from 1 to 9 Handle further interrupts (if existing). 7 The appropriate interrupt service routine is identified and started based on the source of the interrupt. 4 The interrupt service routine is terminated with a special command (return from interrupt, RTI). 5 Switch to kernel mode. 2 The state of the running process is saved. 1 Switch to user mode and continue the execution of the interrupted process. 9 The possibly established blocking of further interrupts is released again. 6 If necessary, the handling of further interrupt requests is stopped (blocked). 3 The state of the interrupted process is restored. 8
2. a) Process states: In this task, we work with the process state model known from the lecture. For reasons of clarity, the state "non-existent" has been represented somewhat more compactly than in the lecture (represents two states at once). Likewise, state transition 5 subsumes two activities. Assign the following terms to the respective numbered elements in the process state model (8 points). Term Numbered element scheduler dispatch or interrupt 5 ready 1 wait for I/O or event 6 admitted 4 waiting 3 I/O or event completion 7 exit 8 running 2 b) Explain why there is no direct transition from the state “waiting” to the “running” state. (3 points) The waiting state is in process typically means it is waiting for an event or resource to be available such as user input, data from a file, or other conditions that the process is dependent on. When the event that the process is waiting for is available, it transitions from the waiting state to the running state. The transition involves an external event or an interruption. Therefore, there is no direct transition from the waiting state to the running state.
3. a) Implement a system of three processes which read and write numbers to a file. Use the programming language C for this. Each of the three processes P1, P2, and P3 must obtain 200 times an integer from the file. The file only holds one integer at any given time. Given a file F, containing a single integer N, each process must perform the following steps (25 points): 1. Open F 2. Read the integer N from the file 3. Close F 4. Output N and the process' PID (either on screen or test file) 5. Increment N by 1 6. Open F 7. Write N to F (overwriting the current value in F) 8. Close F
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
b) Briefly describe why the processes P1, P2, and P3 obtain/read duplicates of numbers (why does a particular integer x appear in the output of more than one process)? (3 points) Processes P1, P2, and P3 obtain duplicates of numbers since its all reading and writing to the same files. Each process reads the current value of N, increments it, and then writes it back, which could make it possible for multiple processes to read the same value of N before any of them write the incremented value back to the file. Therefore, this causes duplicates. c) Suggest a solution (you do not need to implement it) to guarantee that no duplicate numbers are ever obtained by the processes. In other words, each time the file is read by any process, that process reads a distinct integer. (2 points) One can locking mechanisms such as file locks to guarantee that there are no duplicate numbers obtained by the processes. This would ensure that only one process at a time can access and modify the file. Once the process acquires the lock, it can read the current value of N, increment it, and then update the modified value back to the file before unlocking for the other processes to repeat these steps. This would prevent multiple processes from reading and writing to the file simultaneously.