0% found this document useful (0 votes)
46 views

OS Final Exam

Uploaded by

Riad Alarifi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

OS Final Exam

Uploaded by

Riad Alarifi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Yemen of Republic ‫الجمهورية اليمنية‬

Ministry of Higher Education & Research ‫وزارة التعليم العالي و البحث العلمي‬
Scientific International University of Twintech ‫جامعة تونتك الدولية لتكنولوجيا‬

Major: BSc (Hons) Business Information Technology Year: 3 Semester: 5


Subject Name: Operating System Lecturer: Dr. Amin Mohamed Shayea
Activity: Assignment Student Name: Ali Derhem Haza Ali Al-Kabashi

Q1: True or False

2 Parallel computing supports more than one task making progress. [F]

8 Deferred cancellation terminates the target thread immediately. [F]

11 Turnaround time is an amount of time a process has been waiting in the ready [F]
queue.
14 Shortest-remaining-time-first is the non-preemptive version of SJF scheduling. [F]

17 A soft real-time system means that the task must be serviced by its deadline. [F]

1
Yemen of Republic ‫الجمهورية اليمنية‬
Ministry of Higher Education & Research ‫وزارة التعليم العالي و البحث العلمي‬
Scientific International University of Twintech ‫جامعة تونتك الدولية لتكنولوجيا‬

Major: BSc (Hons) Business Information Technology Year: 3 Semester: 5


Subject Name: Operating System Lecturer: Dr. Amin Mohamed Shayea
Activity: Assignment Student Name: Ali Derhem Haza Ali Al-Kabashi

19 Non-preemptive scheduling allows a process to be interrupted in the [F]


midst of its execution, taking the CPU away and allocating it to
another process.

21 Virtual address is an alternative name to the physical address in which both [F]
generated by CPU.
22 In modern OS the swapping technique is disabled as default and can [F]
be used unconditionally.
23 Internal Fragmentation can be solved by either compaction or paging [F]
approaches.
Q2: Answer the following questions based on your knowledge and understanding (short
answer)
1 What is the relation between passive and active entity? When the program becomes
process?
Passive entity is program stored on
disk Process is active
Process – a program in execution;
Program becomes process when executable file loaded into memory

2 Describe the parts of process?


 The program code, also called text section.
 Current activity including program counter, processor registers.
 Stack containing temporary data:
 Function parameters, return addresses, local variables.
 Data section containing global variables.
 Heap containing memory dynamically allocated during run time.

3 State the process states; give short description for each?

As a process executes, it changes state

2
Yemen of Republic ‫الجمهورية اليمنية‬
Ministry of Higher Education & Research ‫وزارة التعليم العالي و البحث العلمي‬
Scientific International University of Twintech ‫جامعة تونتك الدولية لتكنولوجيا‬

Major: BSc (Hons) Business Information Technology Year: 3 Semester: 5


Subject Name: Operating System Lecturer: Dr. Amin Mohamed Shayea
Activity: Assignment Student Name: Ali Derhem Haza Ali Al-Kabashi

 new: The process is being created


 running: Instructions are being executed
 waiting: The process is waiting for some event to occur
 ready: The process is waiting to be assigned to a processor
 terminated: The process has finished execution
4 What is the process control block? What are its elements?
Is Information associated with each process (also called task control block)
 Process state – running, waiting, etc.
 Program counter – location of instruction to next execute
 CPU registers – contents of all process centric registers
 CPU scheduling information- priorities, scheduling queue pointers
 Memory-management information – memory allocated to the process
 Accounting information – CPU used, clock time elapsed since start, time limits
 I/O status information – I/O devices allocated to process, list of open files
5 Describe the actions taken by a kernel to context-switch between processes?
When CPU switches to another process, the system must save the state of the old
process and load the saved state for the new process via a context switch.
6 List the scheduling queues. What is the purpose of each queue?
 Job queue – set of all processes in the system
 Ready queue – set of all processes residing in main memory, ready and waiting to
execute
 Device queues – set of processes waiting for an I/O device
 Processes migrate among the various queues
7 Briefly, explain the differences among short-term, medium-term, and long-term
scheduling?
 Short-term scheduler (or CPU scheduler) – selects which process should be
executed next and allocates CPU.
 Medium-term scheduler can be added if degree of multiple programming
needs to decrease.
 Long-term scheduler (or job scheduler) – selects which processes should be
brought into
the ready queue.
8 When and why Context-switch time becomes overhead?
 When the system does no useful work while switching
 Because The more complex the OS and the PCB :the longer the context switch.

3
Yemen of Republic ‫الجمهورية اليمنية‬
Ministry of Higher Education & Research ‫وزارة التعليم العالي و البحث العلمي‬
Scientific International University of Twintech ‫جامعة تونتك الدولية لتكنولوجيا‬

9 What is the difference between independent and cooperating processes? What is


the advantage of cooperating process over independent? List the models used to
communicate the cooperating processes?
Cooperating process can affect or be affected by other processes, including
sharing data while independent process can not affected by other process.
What is the advantage of cooperating process over independent?
 Information sharing
 Computation speedup
 Modularity
 Convenience

4
Yemen of Republic ‫الجمهورية اليمنية‬
Ministry of Higher Education & Research ‫وزارة التعليم العالي و البحث العلمي‬
Scientific International University of Twintech ‫جامعة تونتك الدولية لتكنولوجيا‬

Major: BSc (Hons) Business Information Technology Year: 3 Semester: 5


Subject Name: Operating System Lecturer: Dr. Amin Mohamed Shayea
Activity: Assignment Student Name: Ali Derhem Haza Ali Al-Kabashi

List the models used to communicate the cooperating processes:


 Shared memory
 Message passing

10 State the benefits of using multithreaded in modern operating systems?


 Responsiveness – may allow continued execution if part of process is blocked,
especially important for user interfaces.
 Resource Sharing – threads share resources of process, easier than shared
memory or message passing.
 Economy – cheaper than process creation, thread switching lower overhead
than context switching.
 Scalability – process can take advantage of multiprocessor architectures.

11 List the challenges of using multithreaded with respect to the programmers?


 Dividing Activities
 Balance
 Data Splitting
 Data dependency
 Testing and Debugging
12 What main difference between data and task parallelism?

Data parallelism: distributes subsets of the same data across multiple cores, same
operation on each.
Task parallelism: distributing threads across cores, each thread performing unique
operation.

5
Yemen of Republic ‫الجمهورية اليمنية‬
Ministry of Higher Education & Research ‫وزارة التعليم العالي و البحث العلمي‬
Scientific International University of Twintech ‫جامعة تونتك الدولية لتكنولوجيا‬

13 Assume that, there are 12 tasks, show how these tasks can be executed on single-
core system and 3-cores system? (draw figure to explain the idea)
Single Core

T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12

Multi Core (3)

T1 T4 T7 T10
T2 T5 T8 T11
T3 T6 T9 T12

6
Yemen of Republic ‫الجمهورية اليمنية‬
Ministry of Higher Education & Research ‫وزارة التعليم العالي و البحث العلمي‬
Scientific International University of Twintech ‫جامعة تونتك الدولية لتكنولوجيا‬

Major: BSc (Hons) Business Information Technology Year: 3 Semester: 5


Subject Name: Operating System Lecturer: Dr. Amin Mohamed Shayea
Activity: Assignment Student Name: Ali Derhem Haza Ali Al-Kabashi

14 State the multithreading models?


 Many-to-One
 One-to-One
 Many-to-Many

15 Why many-to-one model cannot get benefit of multicore system?


Because only one may be in kernel at a time.
16 Why the number of threads per process sometimes restricted in one-to-one
multithreaded model?
Because due to overhead.
17 What are the advantages of thread pool? (state two only)
 Usually slightly faster to service a request with an existing thread than
create a new thread.
 Allows the number of threads in the application(s) to be bound to the
size of the pool.
18 What is TLS standing for, what does it do?
Thread-local storage (TLS) allows each thread to have its own copy of data.
19 What are the differences between TLS and local variables?
 TLS visible across s function invocations
 Local variables visible only during single function invocation
20 State the Scheduling Algorithm Optimization Criteria?
 Max CPU utilization
 Max throughput
 Min turnaround time
 Min waiting time
 Min response time
21 Explain the difference between preemptive and non-preemptive scheduling?
Preemptive Scheduling : cutting CPU process to another process.
 Consider access to shared data
 Consider preemption while in kernel mode
 Consider interrupts occurring during crucial OS
activities non-preemptive: waiting to CPU process until its
finished. Is Scheduling under 1 and 4
 Switches from running to waiting state
 Switches from running to ready state
 Switches from waiting to ready
 Terminates

22 What is the solution of starvation problem?


Aging (Increasing the priority of the process as time progresses)
23 How can the logical address space be defined?
The pair base and limit registers can define the logical address space.
By using A pair of base and limit registers

7
Yemen of Republic ‫الجمهورية اليمنية‬
Ministry of Higher Education & Research ‫وزارة التعليم العالي و البحث العلمي‬
Scientific International University of Twintech ‫جامعة تونتك الدولية لتكنولوجيا‬

Major: BSc (Hons) Business Information Technology Year: 3 Semester: 5


Subject Name: Operating System Lecturer: Dr. Amin Mohamed Shayea
Activity: Assignment Student Name: Ali Derhem Haza Ali Al-Kabashi

24 State the stages of address binding of instruction and data?


 Compile time: If memory location known a priori, absolute code can be
generated; must recompile code if starting location changes
 Load time: Must generate reloadable code if memory location is not known
at compile time
 Execution time: Binding delayed until run time if the process can be moved
during its execution from one memory segment to another
25 What the relation between logical and virtual address?
Logical address – generated by the CPU; also referred to as virtual address
26 What is MMU standing for? What is the relation between MMU and
physical addresses?
Is Hardware device (memory management unit)
MMU that at run time maps virtual to physical address.
27 When swapping technique becomes necessary?
If next processes to be put on C is not in memory, need to swap out a process and
swap in target process PU.
28 What is the difference between external and internal fragmentation?
External Fragmentation: total memory space exists to satisfy a request, but
it is not contiguous Load Time.
Internal Fragmentation: allocated memory may be slightly larger than requested
memory; this size difference is memory internal to a partition, but not being
used.
29 State two methods to solve the external fragmentation problem?
 Paging
 Compaction
30 What is the memory stall?
When a processor accesses memory, it spends a significant amount of time
waiting for the-data to become available.
31 What is the Lazy swapper?
Never swaps a page into memory unless page will be needed.
32 What does page fault cause for OS?
If there is a reference to a page, first reference to that page will trap to
operating system.
33 When the demand paging is called pure?

start process with no pages in memory


34 When Copy-On-Write (COW) is needed?

When parent and child processes want to initially share the same pages in memory.
35 When and why page replacement is needed?

Page replacement is needed If There is no available frame in main memory.


To find pages in memory, when these pages are not in use.
8
Yemen of Republic ‫الجمهورية اليمنية‬
Ministry of Higher Education & Research ‫وزارة التعليم العالي و البحث العلمي‬
Scientific International University of Twintech ‫جامعة تونتك الدولية لتكنولوجيا‬

Major: BSc (Hons) Business Information Technology Year: 3 Semester: 5


Subject Name: Operating System Lecturer: Dr. Amin Mohamed Shayea
Activity: Assignment Student Name: Ali Derhem Haza Ali Al-Kabashi

Q3: Applied Algorithms

1 Given the following:

Process Burst
Time

P1 13
P2 5
P3 7
P4 3

Suppose that the processes arrive as: P1, P2, P3 and P4.
1. Draw Gantt chart to schedule aforementioned processes based on
FCFS algorithm.
2. Compute the turnaround time for each process.
3. Compute the average turnaround time.

1-
P1 P2 P3 P4
0 13 18 25 28
2-
p1=1
3
P2=1
8
P3=2
5
P4=2
8
3- Average turnaround time= (13+18+25+28)/4=21

9
Yemen of Republic ‫الجمهورية اليمنية‬
Ministry of Higher Education & Research ‫وزارة التعليم العالي و البحث العلمي‬
Scientific International University of Twintech ‫جامعة تونتك الدولية لتكنولوجيا‬

Major: BSc (Hons) Business Information Technology Year: 3 Semester: 5


Subject Name: Operating System Lecturer: Dr. Amin Mohamed Shayea
Activity: Assignment Student Name: Ali Derhem Haza Ali Al-Kabashi

2 Given the following:

Process Arrival Burst


Time Time

P1 0 10
P2 2 7
P3 5 3
P4 6 2

Draw Gantt chart to schedule aforementioned processes based on SJF algorithm


and compute the average of waiting time and the average of turnaround time in
case of.
a. Non-preemptive.
b. Preemptive.

a- Non-preemptive
P1 P4 P3 P2
0 10 12 15 22

Waiting time = (0+10+12+15)/4=6


Turnaround = (10-0)+(12-6)+(15-5)+(22-2)=46/4 ==11.5 end time – arrival time

b- Preemptive
P1 P2 P3 P4 P2 P1
0 2 5 8 10 14 22

Waiting time = (12+5+0+2)/4=4.75 end time – arrival – burst time


Turnaround = (22+12+3+4)/4=10.25 end time – arrival time

10
Yemen of Republic ‫الجمهورية اليمنية‬
Ministry of Higher Education & Research ‫وزارة التعليم العالي و البحث العلمي‬
Scientific International University of Twintech ‫جامعة تونتك الدولية لتكنولوجيا‬

Major: BSc (Hons) Business Information Technology Year: 3 Semester: 5


Subject Name: Operating System Lecturer: Dr. Amin Mohamed Shayea
Activity: Assignment Student Name: Ali Derhem Haza Ali Al-Kabashi

3 Given two memory partitions of 600 KB and 500 KB (in order); and two processes
p1=350 KB, and p2=540 KB.
Answer the following questions accordingly.
1- How would each of the first-fit, best-fit, and worst-fit algorithms place the
processes?
a- p1 and p2 came in order.
b- p1 and p2 came in
reverse order.

A-In order

BEFORE FIRST-FIT BEST-FIT WORST-FIT


KB600 P1 P2 P1
500KB x P1 x
There is no space There is no space

B-Reverse order

Before Allocation After Allocation


First-fit Best-fit Worst-fit

600K P2 P2 P2
B

500K P1 P1 P1
B
4 Given the following datum; calculate the internal fragmentation and the number of pages needed for
process p.
Process size = 51M.
Page size = 4M.? number of pages = process size / page size
Number of pages= 51/ 4 =12.75 so the required pages is 13 12 *4 = 48 
51- 48=3 Internal fragmentation = 4 - 3 = 1m

11
Yemen of Republic ‫الجمهورية اليمنية‬
Ministry of Higher Education & Research ‫وزارة التعليم العالي و البحث العلمي‬
Scientific International University of Twintech ‫جامعة تونتك الدولية لتكنولوجيا‬

Major: BSc (Hons) Business Information Technology Year: 3 Semester: 5


Subject Name: Operating System Lecturer: Dr. Amin Mohamed Shayea
Activity: Assignment Student Name: Ali Derhem Haza Ali Al-Kabashi

5 Computer the Effective Access Time (EAT) when the associative memory used with
the following datum:
Hit rate α= 93%, EAT = hit rate(a) * memory Access + 7% * Associative lookup E
Associative lookup ε= 10 ns for TLB search,
And 0.1 microsecond for memory access
0.1*1000=100ns
EAT=0.93*100+0.10*10=
94ns
6 Compute the Effective Access Time (EAT) using Demand Paging mechanism if the
following info. given:
(unit in nanoseconds for all)
Memory access time = 400 nanoseconds.
Average page-fault service time = 4000
microseconds. One-page fault happens per
10,000 accesses.
4000 *1000 = 4,000,000
EAT = (1-P) * memory access time + P * page fault time

EAT = (1-P) x 400 + P x 4,000,000


= 400 -P400 + P x 4,000,000
= 400 + P ( - 400 + 4,000,000)
 = 400 + P (3,999,600)
 = 400 + P (3,999,600/10,000)
 = 400+ P 399.96
 = P 799.96 /1000 = 0.79996  0.8 microsecaned

one access out of 10,000 causes a page fault


(7.9996) EAT = 8 microseconds.

12
Yemen of Republic ‫الجمهورية اليمنية‬
Ministry of Higher Education & Research ‫وزارة التعليم العالي و البحث العلمي‬
Scientific International University of Twintech ‫جامعة تونتك الدولية لتكنولوجيا‬

Major: BSc (Hons) Business Information Technology Year: 3 Semester: 5


Subject Name: Operating System Lecturer: Dr. Amin Mohamed Shayea
Activity: Assignment Student Name: Ali Derhem Haza Ali Al-Kabashi

7 Consider the following page reference string:


1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6.
How many page faults would occur for LRU, FIFO, and optimal replacement algorithm,
assuming 4, 6, and 7 frames? Remember all frames are initially empty, so your first
unique pages will all cost one fault each.
LRU algorithm:
1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
1 1 1 1 1 1 1 1 6 3
2 2 2 2 2 2 2 2 2
3 3 5 5 3 3 3 6
4 4 6 6 7 7 1
Number of Page faults= ……10….
FIFO algorithm:
1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
1 1 1 1 5 5 5 5 3 3 3 3 1 1
2 2 2 2 6 6 6 6 7 7 7 7 3
3 3 3 3 2 2 2 2 6 6 6 6
4 4 4 4 1 1 1 1 2 2 2
Number of Page faults= …14…….
Optimal Algorithm:
1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
1 1 1 1 1 1 7 1
2 2 2 2 2 2 2
3 3 3 3 3 3
4 5 6 6 6
Number of Page faults= ...8.

13
Yemen of Republic ‫الجمهورية اليمنية‬
Ministry of Higher Education & Research ‫وزارة التعليم العالي و البحث العلمي‬
Scientific International University of Twintech ‫جامعة تونتك الدولية لتكنولوجيا‬

Major: BSc (Hons) Business Information Technology Year: 3 Semester: 5


Subject Name: Operating System Lecturer: Dr. Amin Mohamed Shayea
Activity: Assignment Student Name: Ali Derhem Haza Ali Al-Kabashi

6 FRAMES
FIFO algorithm:

1 2 3 64 2 1 5 2 1 2 3 7 6 3 2 1 2 3 6
1 1 1 11 1 7 7 7 7
2 2 22 2 2 1 1 1
3 33 3 3 3 2 2
44 4 4 4 4 3
5 5 5 5 5 5
6 6 6 6 6
Number of Page faults= ……10….

Optimal Algorithm:

1 2 3 64 2 1 5 2 1 2 3 7 6 3 2 1 2 3 6
1 1 1 11 1 1
2 2 22 2 2
3 33 3 3
44 4 7
5 5 5
6 6
Number of Page faults= ……7….

LRU algorithm:
1 2 3 4 6 2 1 5 2 1 2 3 7 6 3 2 1 2 3 6
1 1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3
4 4 4 7
5 5 5
6 6
Number of Page faults= ……7….

14
Yemen of Republic ‫الجمهورية اليمنية‬
Ministry of Higher Education & Research ‫وزارة التعليم العالي و البحث العلمي‬
Scientific International University of Twintech ‫جامعة تونتك الدولية لتكنولوجيا‬

Major: BSc (Hons) Business Information Technology Year: 3 Semester: 5


Subject Name: Operating System Lecturer: Dr. Amin Mohamed Shayea
Activity: Assignment Student Name: Ali Derhem Haza Ali Al-Kabashi

7FRAMES
FIFO algorithm:
1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
1 1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3
4 4 4 4
5 5 5
6 6
7
Number of Page faults=7

Optimal Algorithm:
1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
1 1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3
4 4 4 4
5 5 5
6 6
7
Number of Page faults=7

LRU algorithm:
1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
1 1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3
4 4 4 4
5 5 5
6 6
7
Number of Page faults=7

15
Yemen of Republic ‫الجمهورية اليمنية‬
Ministry of Higher Education & Research ‫وزارة التعليم العالي و البحث العلمي‬
Scientific International University of Twintech ‫جامعة تونتك الدولية لتكنولوجيا‬

Major: BSc (Hons) Business Information Technology Year: 3 Semester: 5


Subject Name: Operating System Lecturer: Dr. Amin Mohamed Shayea
Activity: Assignment Student Name: Ali Derhem Haza Ali Al-Kabashi

16

You might also like