



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Quiz; Professor: Syrotiuk; Class: Operating Systems; Subject: Computer Science and Engineering; University: Arizona State University - Tempe; Term: Fall 2012;
Typology: Quizzes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




(a) P 1 is blocked since is issued a read command at time 5. (b) P 3 is assumed to be ready since it will execute at time 20. (c) P 5 is ready since its time slice expired at time 15. (d) P 7 is blocked since it issued a read command at time 18. (e) P 8 will terminate at time 38 but since we don’t know anything else about P 8 or whether it terminates normally, it could be in any state.
At time 34:
(a) P 1 is still ready (since nothing else has happened to it). (b) P 3 blocks at time 20, but its read completes at time 33 so it is once again ready. (c) P 5 blocks at time 24 and is swapped out at time 28. At time 34 it is still in the blocked/suspend state. (d) P 7 remains blocked. (e) P 8 will terminate at time 38 but since we don’t know anything else about P 8 or whether it terminates normally, it could be in any state.
At time 49:
(a) P 1 is in the ready state because it’s read completes at time 36. (b) P 3 is still in the ready state. (c) P 5 was in blocked/suspend but it’s write completes at time 40 moving it to the ready suspend state. It is then swapped back in, so it moves to the ready state at time 44. (d) P 7 completes a write at time 48 and so moves from the blocked to the ready state.
(a) The process state transition diagram is given in Figure 3.17. It has 9 states as given in Table 3.9. It is similar to the seven-state transition diagram in Figure 3.9(b). Some differences include:
Created
Sleep, Swapped
Ready to Run In Memory Ready to Run Swapped
Asleep in Zombie Memory
Kernel Running
User Running
Preempted
fork
not enough memory memoryenough (swapping system only)
swap in
swap out
swap out
sleep wakeup wakeup
return
preempt
return to user
system call, interrupt
exit
reschedule process
interrupt, interrupt return
Figure 3.17 UNIX Process State Transition Diagram
Table 3.9 UNIX Process States
User Running Executing in user mode.
Kernel Running Executing in kernel mode.
Ready to Run, in Memory Ready to run as soon as the kernel schedules it.
Asleep in Memory Unable to execute until an event occurs; process is in main memory (a blocked state).
Ready to Run, Swapped Process is ready to run, but the swapper must swap the process into main memory before the kernel can schedule it to execute.
Sleeping, Swapped The process is awaiting an event and has been swapped to secondary storage (a blocked state).
Preempted Process is returning from kernel to user mode, but the kernel preempts it and does a process switch to schedule another process.
Created Process is newly created and not yet ready to run.
Zombie Process no longer exists, but it leaves a record for its parent process to collect.
In UNIX, the process table entry defines the state of a process. The contents of the process table entry are given in Table 3.11 and is considered part of the system-level context of a process, i.e., part of the information needed to manage the process. It contains only part of the elements in the PCB in Table 3.5 (mostly for process identification, but also some process control informa- tion). UNIX also has a “U” (user) area containing the remaining process control information and processor state information; see Table 3.12. (b) In the case the OS you selected is multi-threaded, then some differences between the PCB and TCB are as follows. In general, resources are owned by the process and each thread has its own execution state. A few general comments about each category in Table 3.5:
(b) This should work correctly, because count positives in this specific case does not update global positives, and hence the two threads operate on distinct global data and require no locking. Source: Boehn, H. et al. “Multithreading in C and C++,” February 2007. (c) This transformation is consistent with the C language specification, which addresses only single- threaded execution. In a single-threaded environment, it is indistinguishable from the original.
However, in a multi-threaded environment, the transformed version is quite different, in that it assigns to global positives, even if the list contains only negative elements. The original program is now broken, because the update of global positives by thread B may be lost, as a result of thread A writing back an earlier value of global positives. A thread-unaware compiler has turned a perfectly legitimate program into one with undefined semantics. Source: Boehn, H. et al. “Multithreading in C and C++,” February 2007.
not equal to 10 when the test was performed, but was equal to 10 by the time the value of x was read from memory for printing.
M(x) P1: x = x - 1; 9 P1: x = x + 1; 10 P2: x = x - 1; 9 P1: if( x != 10 ) 9 P2: x = x + 1; 10 P1: printf( "x is %d\n", x ); 10
(b) For x is 8 we need to be more inventive, since we need to use interleavings of the machine instructions to find a way for the value of x to be established as 9 so it can then be evaluated as 8 in a later cycle. Notice how the first two blocks of statements correspond to C source lines, but how later blocks of machine language statements interleave portions of a source language statement.
Instruction M(x) P1-R0 P2-R P1: LD R0, x 10 10 -- P1: DECR R0 10 9 -- P1: STO R0, x 9 9 --
P2: LD R0, x 9 9 9 P2: DECR R0 9 9 8 P2: STO R0, x 8 9 8
P1: LD R0, x 8 8 8 P1: INCR R0 8 9 --
P2: LD R0, x 8 9 8 P2: INCR R0 8 9 9 P2: STO R0, x 9 9 9 P2: if(x != 10) printf("x is %d\n", x); P2: "x is 9" is printed.
P1: STO R0, x 9 9 9 P1: if(x != 10) printf("x is %d\n", x); P1: "x is 9" is printed.
P1: LD R0, x 9 9 9 P1: DECR R0 9 8 -- P1: STO R0, x 8 8 --
P2: LD R0, x 8 8 8 P2: DECR R0 8 8 7 P2: STO R0, x 7 8 7
P1: LD R0, x 7 7 7 P1: INCR R0 8 8 7 P1: STO R0, x 8 8 7 P1: if(x != 10) printf("x is %d\n", x); P1: "x is 8" is printed.