Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Os MidTerm Solution

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Question (1) :

1. An operating system is software that controls and manages the


hardware and separates it from the system applications and it
was introduced to increase hardware utilization and allowing
multitasking safely and effectively.
2. Dual-mode was necessary to implement an os to prevent any
process from accessing any place in memory and changing data
of other processes or from accessing i/o devices because this
might make conflicts when 2 processes are using the same
resource at the same time so we have 2 modes the user mode
can’t access the hardware and have to call the os with SVC and
the operating system in kernel mode to execute the functionality
then will switch the mode back to slave before returning to the
process
3. In both of them, you are calling a function from the os but the
difference is that in system calls you call it by its address directly
ex: 1234 and this cause problems in the future if the address
changes but in SVC you map this address ex: 21 so now you
can call SVC(21) and it will move you to the address 1234 so in
the future if the address changes you will still call the same
function bu calling SVC(21) also svc switch your mode to master
mode and after finishing the function it returns with iret to go
back and continue execution and get the saved flags
4. A process is an execution of a program (a program when it’s
loaded in the memory) and the os responsible for scheduling the
process. the thread is a part of the process so the process can
have many threads and threads can easily share data because
they are part of the same process while it’s much difficult to
share data between processes
5. A program is a set of instructions stored in the hard drive while
the process is a program that loaded to the memory and the
program can be loaded into the memory many times
the program header contains general information about the
program itself (starting address of the program etc.. ) and the
header is not loaded in the memory but the operating system
uses its information
the program body is the instructions that loaded into memory the
PCB (Process control block) contains information about the
process (the process id PID, its state, the data inside registers,
etc..), and each process has PCB and it’s essential in the context
switching.
6. It degrades the system performance because it finishes the
process executions on many steps resulting in total time longer
than what it would have taken if it was executed one time without
the switching
7. The os allows any process to ask the memory in the run time
without limitation so this may cause problems because some
processes might ask for more than the free memory. And that’s
why the medium-term scheduler is important because when the
memory is full it takes a process and change its state to
suspended and free it from the memory and save in the hard
drive in the swapping area and it’s also responsible for getting
the suspended process back to the ready state when the
memory is free enough
8. SISD​ (single instruction single data): the machine capable of
executing single instruction on single data ex: mov ax,2
SIMD​ (single instruction multiple data): the machine capable of
executing single instruction on multiple data ex: the GPU and the
matrix multiplication
MISD​ : (multiple instruction single data): a machine capable of
executing multiple instructions on single data ex: the polynomial
MIMD​ (multiple instructions multiple data) machines are capable
of executing multiple instructions on multiple data because it
contains multiple processors (cores) and the processors either
has distributed memory or shared memory
SMP​(symmetric multi-processing): when having a multiprocessor
and memory access is shared between them and the os treats
all the processors equally because (each processor runs the
same or identical copies of the operating system )
9. Virtualization is running multiple operating systems on the same
machine with their kernel and applications and its type:
Bare-metal Hypervisor: the VMM layer directly above the
hardware and the os is above it
Hosted Hypervisor: the os already installed and the VMM is
above it and then we have the guest os
Para-virtualization: here the guest os is modified so the
performance is enhanced to work directly with the VMM
Full Virtualization: like the para-virtualization but instead of
changing in the os here to change the Hypervisor itself to handle
the traps that will get from the os
10. CISC: includes complex instructions that run on more that one
clock (memory to memory)
RISK: reduced instructions it runs on only one clock (register to
register)
Question (2) :
1)

1
S peedup = B + 1n (1−B)

n= 15
Speedup = 10

1
10 = 1
B + 15 (1−B)
10 10
10B + 15 − 15 B =1
140B = 5
1
B = 28 = 0.0357

a. The speedup for 10 processors


1
1
0.0357 + 10 (1−0.0357)
= 7.56
b. To get speed up of 6
1
6 = 1
+ 1n (1− 28
1
)
28
6 162
28 + 28n =1
1 28 6
n = 162 * (1 − 28 )
n = 7.3 then we need 8 processors

c. The maximum possible speedup is when n =


infinity it will be 1/(1/28) = 28

2)

AMAT = hit rate * hit time + miss rate * miss time


The hit time is the cache time = 0.5
The miss time means we didn’t find it in the cache so we will look in
the memory = 10
The hit rate is given
Miss rate = 1- hit rate

Case of (0.2) → AMAT = 0.2 * 0.5 + 0.8 * 10 = 8.1


Case of (0.6) → AMAT = 0.6 * 0.5 + 0.4 * 10 = 4.3
Case of (0.8) → AMAT = 0.8 * 0.5 + 0.2 * 10 = 2.4
Question (3) :

function​ ​print_primes(){
for​((i​=​2​;i​<=​1000​;i​++​))​{
x=0;
for​((j​=​2​;j​*​j​<=​i;j​++​))​{
if​((i​%​j​==​0​))
​then
x=1
​break
​fi
}
if​((x​==​0​))
​then
​echo​ ​$i
​fi

}
}

function​ ​array_average(){
​read​ -p ​"enter array : "​ -a r;
​ cho​ ​"Array is : ​${r[@]}​;"
e
tot=0
​for​ ​i​ ​in​ ​${r[@]}
​do
​ et​ tot+=​$i
l
​ one
d
count=​${​#​r[@]}
​echo​ ​"the average is : $((​$tot​/​$count​))"​ ​# this will print the average
as integer
​#printf %.10f "$((1000000000 * tot/count))e-9" # this will print the
average as float

}
function​ ​print_even(){
​read​ -p ​"enter 6 numbers in one line : "​ -a r;

​ it also could be done by reading 6 different variables and checking


#
each one of them

​for​ ​i​ ​in​ ​${r[@]​:​0​:​6}​ ​# take only the first 6 numbers in case he nade
nustaje and entered more than 6 variables
​do
if​((i​%​2​==​0​))
​then
​echo​ ​"​$i​"​;
​fi
​done
}

function​ ​create_dirs(){

​for​ ​i​ ​in​ 1 2 3 4 5


​do
mkdir ​"dir_​${i}​"​;touch ​"dir_​${i}​/file_​${i}​"
​ one
d
}

function​ ​check_exist(){
​read​ -p ​"enter file name : "​ f

​if​ [ -f ​$f​ ]
​then
​echo​ ​"the file exists"
​else
​echo​ ​"the file dosen't exists"
​fi

}
read​ -p ​"enter letter "​ X;

case​ ​$X​ ​in

p)
print_primes
;;

a)
array_average
;;

o)
print_even
;;

f)
create_dirs
;;
e)
check_exist
;;
*)
​ cho​ ​"letter is not valid"​;
e
;;
esac

You might also like