0% found this document useful (0 votes)
20 views15 pages

HW 2

The document outlines a series of exercises related to process scheduling in an operating system simulator, detailing the steps to load programs, create processes, and observe their behavior under various scheduling policies such as First-Come, First-Served, Priority, and Round-Robin. It includes specific instructions for monitoring process states, managing execution speed, and utilizing logs to analyze scheduling outcomes. Additionally, it discusses the creation of multithreaded processes and the implications of different scheduling algorithms on process execution and termination.

Uploaded by

Arnold Masmini
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)
20 views15 pages

HW 2

The document outlines a series of exercises related to process scheduling in an operating system simulator, detailing the steps to load programs, create processes, and observe their behavior under various scheduling policies such as First-Come, First-Served, Priority, and Round-Robin. It includes specific instructions for monitoring process states, managing execution speed, and utilizing logs to analyze scheduling outcomes. Additionally, it discusses the creation of multithreaded processes and the implications of different scheduling algorithms on process execution and termination.

Uploaded by

Arnold Masmini
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/ 15

GROUP 5

1.DORCAS KIVUYO : 2022-04-04599


2.SONIA LIMBU : 2022-04-05039
3.ANGEL EMMANUEL : 2022-04-01768
4.JULIET MSELE : 2022-04-
5.HAPPINESS KASAMBALA : 2022-04-03745
6.HILDA GABRIEL : 2022-04-01979
7.KARENBHOKE MASEKE : 2022-04-06412
8.CAREN A CHRISTOPHER : 2022-04-01303
9.DIANA MODEST DEO : 2022-04-01537
10.ARNOLD MASMINI : 2022-04-06484
11.LOUIS KONYOKA : 2022-04-04729
12.KENNETH MARTIN KILIMBA : 2022-04-04249

Investigating Process Scheduling 1


Loading programs and creating processes
OSS requires one or more programs to be loaded before it can run the
simulations. You do this by clicking on the LOAD PROGRAM… button
in the PROGRAMS view (see Image 6 above). After successfully
loading a program you need to create one or more instances of it as
processes. Follow the steps below to do this
1. Click on LOAD PROGRAM… button
2. Select the file FORNEXTLOOP.sas - you'll see the entry FORNEXT
appear in the PROGRAMS view in Program Name column
3. Click on CREATE PROCESS button
1. Can you explain the result of action 3 above?
After creating the new process , the ready queue was filled with process
one named fornextloop..
Running processes
Once a process is created it is a candidate for scheduling to run by the
operating system. In a real operating systems the scheduler is always
active looking for the next process, if one is available, to run as soon as
the CPU becomes available. In our simulator the user must manually
start the scheduler. To start the simulator do the following
Click on the START button in the Control view (see Image 5 above)
2. Can you explain what happened?
The process 1 was sent to the CPU , the running process state.
3. What kind of information is displayed about a process?
Process id
Program name
Process State
Process Memory in stages
Process Priority
Process Average Burst Kicks
Swap
Process name
Assigned CPU to process
Process Parent Process Id

Operating system log


The simulator maintains a log of events of interest. To show the log do
the following
Click on the VIEW LOG… button in the Control view (see Image 5)
What sort of information is displayed in the log window?
Avg waiting time,Avg burst time, Scheduling Scheme, Process
Transition … .

Investigating different scheduling policies


The simulator provides different scheduling options. These are
selectable by the user in Policies view (see Image 4 above). The
following exercises are designed to investigate different scheduling
algorithms.
What is an algorithm?
Is a step by step procedure or set of rules to perform a specific task.
1. Select the First-Come, First -Served (FCFS) policy
2. Create two processes
3. Set the speed of execution of processes to Fast (slider at top)
4. Start the scheduler
5. Wait until all processes normally terminate
Explain the behaviour of this scheduling policy.
The first process created was taken to the running processes state after
its termination the second process created went to the running
processes state and also terminated. Execution occurred in sequence of
what process was created first.
6. Select the Priority (non-preemptive) policy
7. Create a processes with priority 3
8. Create a process with priority 2
9. Create a process with priority 4
10. Create a process with priority 3
Explain the behaviour of this scheduling policy.
The first process moved to CPU and finished execution then, the
process with highest priority that is 2 moved to the CPU then priority 3
then lastly priority 4.
11. Set the speed of execution of processes to Fast (slider at top)
6 12. Start the scheduler
13. Wait until all processes normally terminate
14. Select Round-Robin scheduling policy
15. Select "10 ticks" as the time slot
16. Create three processes
17. Start the scheduler
18. Wait for a short time (2 seconds?) then click on the SUSPEND
button in Control view (see Image 5).
19. Select a process in the Ready Processes view (i.e. the ready
queue) and click on the PCB… button in the same view.
What do you see?
There is three views,PCB info ,program stack and register set as follows;
Observe the number against the PC Register. What is
the significance of this number?
This is the Program Counter Register, the number is 17 meaning it
currently points at instruction number 17 in the process memory, its
significance is;
 Facilitates context switching,since PC value is saved in PCB when
process resumes it ensures the CPU starts from instruction 17
maintaining process continuity.
 Tracks Execution progress,this helps OS resume the process from
where it left off.
 Support debugging ,if process crashes the PC value helps identify
the specific point in the code where issue occurred.
 Ensure instructions as executed in the correct order unless
explicitly modified.
What other important information do you see about this
process in the displayed window?
Process id, Program name, process state, avg burst time, avg waiting
time, priority, memory size, SR register
20. Now, click the RESUME button
21. Wait until all processes normally terminate
Explain the behaviour of this scheduling policy.
Process one was moved to the running process then returned to waiting
state while process two in running process then also returned back to
waiting state while process three moved to the running process then
also returned and process one back again to the running process this
cycle went on for some time then process one terminated followed by
process two then process three.
22. Select Priority (pre-emptive) scheduling policy
23. Set speed of execution of processes to near the Slow end
24. Create a processes with priority 2
25. Create a process with priority 3
26. Start the scheduler
27. Now, create a process with priority 1
Which process is running?
Process with Priority 1
Before process with priority one was created process one with priority
was running but as soon as process three with priority one was created
and in the waiting stage it directly went to the running process.

Which processes are in the ready queue?


Process1 with priority 2 and Process2 with priority 3
Explain the behaviour of this scheduling policy.
The process with the lowest priority number is given priority to be
executed first in the CPU, even if a process is already in the CPU it will
be emptied and the process with higher priority is executed.
28. Wait until all processes normally terminate
29. Select the First-Come, First -Served (FCFS) policy
30. Create two processes
31. Set the speed of execution of processes to Fast (slider at top)
32. Start the scheduler
33. Now, in the RUNNNING PROCESSES view (see Image 3), select
Waiting Time of 10 seconds then click on the WAIT button.
34. Now observe the behaviour of the process which was running prior
to you clicking the WAIT button (you will have to wait a short while).
Explain the behaviour of this process.
The process in ready queue went to the running queue then ,
the process was taken to the waiting queue and stayed for some time
then went back to the ready queue then the running process state.
What state transitions did it go through?
READY QUEUE---RUNNING PROCESS---WAITING QUEUE---
READY QUEUE----RUNNING PROCESS
35. Wait until all processes normally terminate
36. Now, view the log and trace the results of your actions so far.

Additional exercises (optional)


When a process is created, it starts in the ready queue, then, at some
stage, it is scheduled to run and starts running. This process can either
terminate naturally (its code decides when) or by external intervention,
e.g. the user or the OS.
1. Select the First-Come, First -Served (FCFS) policy
2. Create two processes
3. Set the speed of execution of processes to Slow (slider at top)
4. Start the scheduler
5. Click on the KILL button
What happened?
Only the process I clicked kill on was terminated but the other process
continued execution.
Is another process running?
Yes, the process that was in the ready queue.
6. Wait until the process normally terminates
Remove the program by clicking on the REMOVE PROGRAM button
in
the PROGRAMS view (see Image 6).
7. Click on LOAD PROGRAM… button
8. Select the file THREADTEST.sas - you'll see the entry
THREADTEST appear in the PROGRAMS view in Program Name
column
9. Click on CREATE PROCESS button
10. Select Round-Robin scheduling policy
11. Select "10 ticks" as the time slot
12. Set the speed of execution of processes to Fast (slider at top)
13. Start the scheduler
14. Observe what happens. When three processes are created, click on
the SUSPEND button.
15. From Control view, click on the VIEW PROCESS LIST… button.
16. Click on the PROCESS TREE… button.
What do you see? Can you explain what you see?
I see that the the parent process THREADTEST created P1T0 child
process which also created a child process P1T0T1(subchild for
THREADTEST process)that also created another child P1T0T1T2 .
Why are there three processes when you created only one?
Multithreading:
The program was designed to use threads for concurrent execution.

Investigating Process Scheduling 2


Lab Exercises - Investigate and Explore
Start the CPU simulator. You now need to create some executable code
so that it can be run by the CPU under the control of the OS. In order to
create this code, you need to use the compiler which is part of the system
simulator. To do this, open the compiler window by selecting the
COMPILER… button in the current window. In the compiler window,
enter the following simple code in the compiler source editor area (under
PROGRAM SOURCE frame title):
program LoopTest
I=0
for N = 0 to 40
I=I+1
next
end
Now you need to compile this in order to generate the executable code.
To do this, click on the COMPILE… button. You should see the code
created on the right PROGRAM CODE view. This code needs to be
loaded in memory so that the CPU can execute it. To do this, click on the
LOAD IN MEMORY button in the current window. You should now
see the code loaded in memory ready to be executed.
We are now going to use the OS simulator to run this code. To enter the
OS simulator, click on the OS… button in the current window. The OS
window opens. You should see an entry, titled LoopTest, in the
PROGRAM LIST view.
Now that this program is available to the OS simulator, we can create as
many instances, i.e. processes, of it as we like. You do this by clicking on
the CREATE NEW PROCESS button. Repeat this four times. Observe
the four instances of the program being queued in the ready queue
represented by the READY PROCESSES view. Make sure the First-
Come, First-Served (FCFS) option is selected in the
SCHEDULER/Policies view. At this point the OS is inactive. To
activate, first move the Speed slider to the fastest position, then click on
the START button. This should start the OS simulator running the
processes. Now, follow the instructions below without any deviation:
1. Make a note of what you observe (you need to concentrate on the two
views: RUNNING PROCESSES and the READY PROCESSES during
this period).
The first process created was the first to move to the running
processes ,then each process was executed in order of how it was
created.
2. When all the processes finished, do the following. Select the Priority
(static) option in the SCHEDULER/Policies view. Then select the Non-
preemptive option in the SCHEDULER/Policies/Priority Type frame.
Create three processes with the following priorities (use the Priority
drop-down list in the PROGRAM LIST/Processes view: 3, 2, 4. Slide
the Speed selector half-way down, then hit the START button. While the
first process is being run do the following. Create a fourth process with
priority 1. Make a note of what you observe.
The current process was not interrupted , but after it terminated the
process with high priority was next so process4 with priority 1 was
next then process 2 with priority2 and lastly process 3 with priority 4
3. Now, 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). Next, select the Pre-emptive option in the
SCHEDULER/Policies/Priority Type frame. Create three processes
with the following priorities: 3, 2, 4. Slide the Speed selector half-way
down and then hit the START button. While the first process is being run
do the following. Create a fourth process with priority 1. Make a note of
what you observe.
The current process was interrupted ,the process with high priority
moved in the CPU running process that is process4 with priority 1
then process 2 with priority2 and lastly process 3 with priority 4

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.

You might also like