HW 2
HW 2
4. Slide the Speed selector to fastest position and wait for the processes to
complete (or use the KILL button to terminate the processes one by
one). Select the Round-Robin (RR) option in the
SCHEDULER/Policies view. Then select the Non-preemptive option in
the SCHEDULER/Policies/Priority Type frame. Create four processes
and hit the START button. Make a note of what you observe.
Process executed in a circular manner,process1 moved to CPU for
some time then went back to ready queue then process 2 did the
same ,and all the other process followed this trend until process one
terminated , then followed by process two then the rest in this order.
5. Wait for all the processes to complete. Go to the compiler window (use
the COMPILER… button in the GO TO frame for this). Click the NEW
button in the PROGRAM SOURCE view and enter the following source
code:
program LoopForeverTest
N=0
while true
N=N+1
wend
end
Compile this code and load it in memory as previously described above.
Go to the OS window (use the OS… button for this). You should now see
an additional entry in the PROGRAM LIST view titled
LoopForeverTest. Select this entry by clicking on it. We are now going
to create processes of this program but this time we will assign a lifetime
(in seconds) to each. We’ll create three processes with the following
lifetime values (use the Lifetime text box for the values and also select
the Secs radio button): 10 seconds, 32 seconds, 6 seconds. Now, we are
going to select the time slot value. To do this select 4 seconds from the
3 drop-down list in SCHEDULER/Policies/RR Time Slice view. Hit the
START button and wait until all processes finish.
Open the OS Activity Log window by clicking the VIEW LOG… button
in the SCHEDULER/Control & Monitor view. Observe the relevant
log entries and check out the sequence of the running processes and note
the time spent by each process during each running state.
The RR scheduler effectively manages the processes, switching
between them based on their time slices and lifetimes. The process
were executed in multiple time slices , The shorter-lived processes
were completed first.
6. Now, go to the compiler and enter the following code in the source
code editor. You need to click on the NEW button to start a new source
code tab in the editor:
program LoopForeverTest2
while true
n=n+1
i=i+n
p=n+i+5
wend
end
Compile this new source and load in memory. Go to the OS simulator.
You’ll observe a third entry in the PROGRAM LIST view titled
LoopForever2. Click on the entry LoopForever and create a process.
Click on LoopForever2 and create a process of it. There should now be
two processes in the ready queue. Make sure the Round Robin
scheduling is selected, the priority type is Non-preemptive and that the
RR Time Slice is 10 ticks (you can select this from the drop-down list).
Put the simulation speed to half-way (using the speed selector).
Finally, go to the CPU simulator window, click on the SHOW
PIPELINE… button and in the new window check the No instruction
pipeline check box. Close this window and go back to the OS Simulator
window.
Now we are ready for the next experiment. Do the following:
1. Select each process in turn and click on the PCB… button. Observe
the values of the PC Registers in each case and make a note.
Both the PC registers are zero.
2. Click on the START button and keep your mouse on the
SUSPEND button but NOT clicked yet.
3. As soon as the currently running process is put back in the ready
queue, click on the SUSPEND button.
4. Select the process in the ready queue and click on the PCB…
button in the ready queue. Make a note of the PC Register value.
The PC register is 17.
5. Now, select the Suspend on run check box in the RUNNING
PROCESSES view. Slow down the OS simulation further (say two
thirds down the scale). Click on the RESUME button and observe
when the queued process is put back in running state at which
point the simulation will be automatically suspended. Keep your eye
on the PC Register box in the CPU simulator window (you may
have to re-arrange the simulation windows for this). Now, click on
the RESUME button in the OS simulator. Make a note of the value
in the PC Register when it changes to a new value.
The PC Register value is 51 after suspending state again.
Then in the CPU simulator the registers changed interchangeably
36,41,42,11,17,21,26,37,42,17,56,61,7,2,77,0,6,15,21………
Comment on this value and explain what is happening.
When a context switch occurs, the CPU needs to save the current
state of the running process, including the values of its registers. This
saved state is stored in the process's Process Control Block (PCB).
Then, the CPU loads the saved state of the next process to be
executed, restoring its registers to their previous values.