ch1: explain how operating system works as a resource

34
Ch1: Explain how operating system works as a Resource manager with a suitable diagram: Answer: OS manager all resource: - process management Memory management - - I\O management - File management

Upload: others

Post on 20-May-2022

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Ch1: Explain how operating system works as a Resource

Ch1:

Explain how operating system works as a Resource

manager with a suitable diagram:

Answer:

OS manager all resource:

- process management

Memory management -

- I\O management

- File management

Page 2: Ch1: Explain how operating system works as a Resource

Evolution of operating system:

1) simple batch system:

-batch job together

- job read via punch card

2)Multiprogramming OS:

- when one job needs to wait for I\O the C.P.U can switch to

other job.

Program A :

Program B :

Combined :

3)Time Sharing: 1980 – now

C.P.U time is shared among multiple job.

Multiple user access the system .

Examble:

In time sharing multiple user access system simultaneously.

Wait Wait RUN RUN

Wait RUN Wait RUN

Wait RUN A

A

RUN B

Page 3: Ch1: Explain how operating system works as a Resource

Q:what is system call: write the types of system call:

Answer:

system call is : interface between process and operating system.

Types of system call:

- Process control.

- Device management.

- File management.

- Communication.

Q:What is kernel:

Answer : portion of operating system that is in main

memory (RAM).

It is also called "Nucleus".

Example: kernel: is also called "Nucleus"

Memory types:

- Ram

- Rom

- Cache

"The end ch1 "

RAM Cache CPU

Page 4: Ch1: Explain how operating system works as a Resource

Ch2: " File Management System"

Q1: What is file , write the properties of file.?

Answer:

File is the central element of an application.

Properties of file:

- Long term existence.

- Sharable.

- Structure.

Q2:Write the operations on file: also on directory

- Create.

- Delete.

- Modify.

- Open.

- Read.

- Close.

Q3: Explain structure of file:

Field: basic element of data.

File: collection of similar records.

Record: collection of related fields.

Database: collection of related files.

FILE

file record database field

Page 5: Ch1: Explain how operating system works as a Resource

Example:

Q4: What is directory.? Write the information of directory?

Answer:

Directory: is a file owned by operating system.

Information of directory:

File name - File types - File organization

Q5:What are address information of directory.?

Answer:

- Volume

- Size used

- Size allocated

Q6:What are the access control information of directory.?

Answer:

- Owner: grant / deny access to user

- Access information: include username and password.

- Action’s: reading , writing , sharable

STUDENT

Name Address ID Course

ALI

HMAD

20110012

20104098

Jazan

abha

OS

OS

Records

Page 6: Ch1: Explain how operating system works as a Resource

Q7:Explain file organization and its types.?

Answer:

- File management refers to logical structure of file.

- A way to access the file.

Types of file organization:

- Pile

- Indexed file

- Sequential file

- Indexed sequential file

- Direct file

Pile:

- Data are collection in the order they arrive.

- N0 structure.

- Search is difficult.

Indexed file:

- May contain a partial index

Sequential file:

- Fixed format used for record.

- Record are stored in key sequence.

Index sequential file :

- Maintain the key of sequential of file.

- It is random accessed.

Direct or hashed file:

- Directly access a block at known address.

- Key field required for each record.

Page 7: Ch1: Explain how operating system works as a Resource

Q8:Describe UNIX file management.?

Answer:

*UNIX have 6 types of files:

- Regular.

- Directory.

- Special.

- Named pipes.

- Links.

- Symbolic links.

Q9: What are the features of NTFS(windows file system).?

Answer:

- Recoverable.

- Security.

- Large disk or large file.

- Compression and encryption.

Q10:What is block.? Write the common approaches.?

Answer:

Block are the unit for I\O with secondary storage.

*Approaches:

- Fixed length blocking.

- Variable length spanned blocking.

- Variable length un spanned blocking.

Page 8: Ch1: Explain how operating system works as a Resource

Discuss file allocation method.

Answer:

There are three methods:

Contiguous: single set of block is allocated to a file at the

time of creation.

Chained: allocation on basis of individual block.

Indexed: file allocation table contains a separate one level

index for each file.

"The end ch2 "

Page 9: Ch1: Explain how operating system works as a Resource

Ch31 : " process management".

Process: A process is a program in execution .

A instance of program running in computer.

What are the process element:

- Program code.

- Data.

- Attributes.

Q1:When process is running , What are the elements.?

Answer:

- Identifier

- State

- Priority

- Program counter

- Memory pointer

- I\O status information

- Accounting information

Q2:What is PCB "Process Control Block".?

- PCB is data structure to store the process elements.

- Create and manage by OS.

Diagram " process control block ".>>>

process program CPU

Page 10: Ch1: Explain how operating system works as a Resource

Q3: PCB Used to store the process element.

Two state process model:

- Running

- Not running

Q4:What is dispatcher.?

Dispatcher is a program which is used to switch the process.

Q5:Explain the five state process model.?

Diagram " Five state process model "

Five state:

1) New : creation of process.

2) Ready : is in process.

3) Running : is in CPU or memory.

4) Blocked : suspended.

5) 5) Exit

Dispatcher

ENTER

Pause

Not Running Running

EXIT

Admit Release Dispatch New Ready Running Exit

Blocked

Time out

Event

Wait

Event

Occurs

Page 11: Ch1: Explain how operating system works as a Resource

Q6:What are reason for process suspension.?

- Swapping

- Timing

- Other OS reason

- Parent process request

Q7:Process Table.?

Answer:

Current state

Process ID

Location in memory

Q8: What are the process attributes.?

- Process ID.

- Process state information.

- Process control information.

Q9:What are the role of PCB.?

- It defines the state of the OS.

- It requires protection.

Q10:Define UNIX process.?

A process in UNIX is a state of data structure that provide

OS with all the information to manage.

- User level context.

- Register level context.

- System level context.

Page 12: Ch1: Explain how operating system works as a Resource

Ch32: " Thread "

Q1:What is thread:

- A thread is a light weight process.

- It provides a way to improve application performance

through parallelism.

Stack

Data

Code

Q2:Explain user level thread (ULT).?

Answer:

Diagram " U.L.T "

Stack

Data

Code

Thread

Multithread Single thread

Page 13: Ch1: Explain how operating system works as a Resource

Q3:What are the difference between thread and process.?

Thread

Process

1) It is light weight. 1) I t is heavy weight.

2) Thread switching doesn't

need interaction with OS.

2) Process switching needs

interaction with OS.

3) Use less resources. 3) Use more resources.

Q4:What are advantages of threads.?

- Minimize context switching time.

- Provide concurrency within a process.

- Efficient communication.

- More economical to create context switch thread.

*types of thread:

- User level threads (ULT) – user manage thread.

- Kernel level threads (KLT) – OS manage thread.

Q5:Advantage of ULT (user level thread).?

- Doesn't require kernel mode permission.

- Run on any OS.

- Fast to create and manage.

Page 14: Ch1: Explain how operating system works as a Resource

Q6:Explain multithreading model.?

Some OS manage more ULT and KLT.

Example : solaris

1) Many to many.

- User thread is equal or smaller than kernel thread.

User space

Kernel space

thread thread

CPU CPU

CPU

CPU

CPU

CPU

Page 15: Ch1: Explain how operating system works as a Resource

2) Many to one model:

- Map many user level thread to one kernel thread .

- Management is done in user space .

- Only one thread can access the kernel at time.

Example "in exam "

- In many to one mode only one thread can access the

kernel at a time.

3) One to one.

CPU CPU CPU

Kernel space

User space

thread thread

User space

Kernel space

CPU CPU

thread thread

- One ULT and K LT.

CPU

Page 16: Ch1: Explain how operating system works as a Resource

Q4:What are the difference between ULT and KLT.?

ULT

KLT

1) Faster to create and manage

1) Slower to create and manage

2) Implementation is by user

level.

2) OS create KLT.

3) Run on any OS

3) Specific to OS.

4) Multithread application

can not take advantage of

multiprocessing.

Kernel routine can be

multithreaded.

Page 17: Ch1: Explain how operating system works as a Resource

Q5:Draw the diagram of LINUX process thread model.?

Answer:

Diagram " UNIX process model "

"The end ch3

Page 18: Ch1: Explain how operating system works as a Resource

Ch4: " scheduling "

Q1:What is scheduling.?

Scheduling is: the process which allows to utilization the

CPU until it completes and other process to hold or wait.

scheduling

non preempting keep

CPU until it completes

Example :

1) Non preemitive:

- FCFJ

- SJF

2) Preemitive :

- Round robin

- Priority scheduling

Preempting release CPU

even thought it is neither

completed nor blocked

Page 19: Ch1: Explain how operating system works as a Resource

Scheduling Algorithm:

1-FCFS First Come First Serve.

*grant chart:

P1 P2 P3 P4

0 40 23 13 19

Waiting time of P1=0

Waiting time of P2=40

Waiting time of P3=40+23=63

Waiting time of P4=63+13=76

*Average waiting time= 0+40+63+76 / 4

= 179 / 4 = 44.75 m\sec

Process Burst time

P1 40

P2 23

P3 13

P4 19

Page 20: Ch1: Explain how operating system works as a Resource

Q2: Assume that there are three process P1,P2,P3, that

arrive at CPU for processing .Each process has its own burst

time as shown in table draw grant chart and calculate the

average waiting time in FCFS.?

Process Burst time

P1 24

P2 3

P3 3

*Grant chart:

P1 P2 P3

0 24 3 3

Waiting time of process P1=0

Waiting time of process P2=24

Waiting time of process P3=24+3= 27

*Average waiting time= 0+24+27 / 3

= 51/3 = 17 m/sec

- FCFS: In this scheduling CPU is assigned the process in

order " First Come First Serve".

- Grant chare : grant chart is a bar chart that shown start

and finish time of each process.

Page 21: Ch1: Explain how operating system works as a Resource

2- SJF Shortest Job First

Process Burst time

P1 40

P2 23

P3 13

P4 19

*Grant chart:

40 23 19 13 0

Waiting time of P1=13+19+23=55

Waiting time of P2=13+19=32

Waiting time of P3=0

Waiting time of P4=13

*Average waiting time= 55+32+0+13 / 4

= 100 / 4 = 25 m/sec

P4 P3 P2 P1

Page 22: Ch1: Explain how operating system works as a Resource

Q3:Assume that three are four process P1,P2,P3,P4,that

arrive at CPU for processing . Each process has its own

burst time as shown in table. Calculate average waiting time

and grant chart in SJF.?

*Grant chart:

P4 P1 P3 P2

0 3 6 7 8

Waiting time of P1=3

Waiting time of P2=3+6+7=16

Waiting time of P3=3+6=9

Waiting time of P4=0

*Average waiting time = 3+16+9+0 / 4

= 28 /4 = 7 m/sec

SJF : In this scheduling , when CPU is available . it is assigned

to smallest process first.

Process Burst time

P1 6

P2 8

P3 7

P4 3

Page 23: Ch1: Explain how operating system works as a Resource

3- Priority scheduling :

Process Burst time Priority

P1 10 3

P2 1 1

P3 2 4

P4 1 5

P5 5 2

*Grant chart:

P2 P5 P1 P3 P4

0 1 5 10 2 1

Waiting time for P1=6

Waiting time for P2=0

Waiting time for P3=16

Waiting time for P4=18

Waiting time for P5=1

*Average waiting time = 6+0+16+18+1 / 5

= 41 / 5 = 8.2 m/sec

Q4:Explain priority scheduling.?

A priority is associated with each process and CPU is

allocated to the priority with highest priority.

Page 24: Ch1: Explain how operating system works as a Resource

4-Round Robin Time sharing

Time quantum= 4

Process Burst time

P1 24

P2 3

P3 3

*Grant chart:

P1 P2 P3 P1

0 4 4+3=7 7+3=10 10+20=30

Waiting time for P1=10-4=6

Waiting time for P2=4

Waiting time for P3=7

*Average waiting time = 6+4+7 / 3

= 17 / 3 = 5.6 m/sec

Page 25: Ch1: Explain how operating system works as a Resource

Calculate average waiting time in Round Robin for below.?

Time quantum= 2

Process Burst time

P1 24

P2 3

P3 3

*Grant chart:

P1 P2 P3 P1 P2 P3 P1

0 2 4 6 8 9 10 30

Waiting time for P1=(6-2)+(10-6)=8

Waiting time for P2=8-4=4

Waiting time for P3=9-6=3

*Average waiting time = 8+4+3 / 3

= 15 / 3 = 5 m/sec

Page 26: Ch1: Explain how operating system works as a Resource

Q5:Calculate average waiting time in Round Robin for

below.?

Time quantum= 2

Process Burst time

P1 8

P2 4

P3 9

P4 5

*Grant chart:

P1 P2 P3 P4 P1 P2 P3 P4 P1 P3 P4 P1 P3

0 2 4 6 8 10 12 14 16 18 20 21 23

Waiting time for P1= (8-2) + (16-8) + (21-16) =19

Waiting time for P2= (10-4) = 6

Waiting time for P3= (12-6) + (18-12) + (23-18) =17

Waiting time for P4= (14-8) + (20-14) = 12

*Average waiting time =19+6+17+12/ 4

= 54/4 = 13.5 m/sec

" The end ch4 "

26

Page 27: Ch1: Explain how operating system works as a Resource

Ch5: " Dead Lock "

Q1:Define Deadlock :

A process request resources , if the resource is not available

that time ,the process enter a wait state .This situation is

called deadlock .

Q2: What is the sequence in which resource may utilized .

Answer:

1) Request

2) Use

3) Release

Q3:What are the condition under which a deadlock in round

robin for below arise.?

- Mutual Exclusion.

- Hold and wait.

- Non preemption.

- Circular wait.

Q4:What are the methods for dealing deadlock problem.?

- Use a protocol that ensure there should be no deadlock

- Allow the system to recover from deadlock.

- Ignore the problem all together and pretend that

deadlock never happen.

Page 28: Ch1: Explain how operating system works as a Resource

Q5: What are the reasons for deadlock . Explain any two .

1) Mutual Exclusion.

Only one process at time can use resources

2) Hold and wait.

A process holding at least one resource is waiting to

acquire additional resource.

3) Non preemption.

A process can be released only until its completed.

4) Circular wait.

Q6: Explain resource allocation Graph ,with examples.

Resource allocation graph tracks which resources is held by

which process and which process is waiting for a resources it

is tool for detecting deadlock .

Process Resource

Examples:

R1

R1

2)

1) P1 is requesting resource R1

R1 P1

P1 is Using resource R1

P1 is requesting resource R2

R2 3)

P1 P2 P2 is Using resource R2

P1 is Using resource R1

P1

Page 29: Ch1: Explain how operating system works as a Resource

Q7: Assuming the operating system detects the system is

deadlocked .What can the OS do to recover from deadlock ?

1) Killing the deadlock process.

2) Rolling Back

3) Preemption

" The end ch5 "

Ch6: " Memory Management "

Q1 : What are the difference between logical and physical address?

Logical Physical

It is the address generated by CPU It is the address seen by Memory

Memory

Volatile example RAM

(Main Memory)

Non Volatile example ROM

(Permanent Memory)

Page 30: Ch1: Explain how operating system works as a Resource

Contiguous allocation Not Contiguous allocation

Q2 :What are the differences between Contiguous and

Not Contiguous allocation ?

Answer :

Contiguous Not Contiguous

A program occupies

contiguous block by

memory

A program occupies

several block and not

necessary to adjacent

block

Faster Slower

More waste in memory Less waste in memory

Q3 : Suppose that we have free segment of size 6,17,25,14

and 19 . Place a program with size 13 kb in free segment

using First Fit , Best Fit , Worst Fit .

Answer :

13 KB

P1

P2

P3

P1

P2

P3

P4

6 KB

17 KB

25 KB

14 KB

19 KB

First Fit

Worst Fit

Best Fit

Page 31: Ch1: Explain how operating system works as a Resource

Q4: Explain page placement Strategies :

Answer :

1) First Fit :

place in first hole that is big enough . (it is faster)

2) Best Fit :

Allocate the smallest hole that is big enough .

3) Worst Fit :

Allocate the largest hole .

In exam :

In ___________ strategy . Wastage of memory is more .

Q5 : What are the difference between segmentation and

paging ?

Answer :

Segmentation Paging

1- Variable size block in memory 1- Fixed size block

2- Address generate by CPU is

divided into segment number .

2- Address generated by CPU is

divided into page number .

3- Physical address = segment+base 3- Physical address =

page size*frame number+off set

Worst Fit

Page 32: Ch1: Explain how operating system works as a Resource

page replacement algorithm

1) FIFO

2) LRU

3) OPTIMAL

FIFO example :

Q6: Consider the following page reference using three

frames.Find the page fault using FIFO algorithm .

8,2,0,1,2,3,5,0,1,3

Answer:

8 8 8 1 1 1 1 0 0 0

2 2 2 2 3 3 3 1 1

0 0 0 0 5 5 5 3

Number of page fault = 9

1 2 3 4 X 5 6 7 8 9

Page 33: Ch1: Explain how operating system works as a Resource

LRU example 1 :

Q7: Consider the following page reference using four

frames.Find the page fault using LRU algorithm .

5,2,5,1,4,5,2,0,4,2,3,1,2,1,0,0,2,4,5,1

5 5 5 5 5 5 5 5 5 5 3 3 3 3 3 3 3 4 4 4

2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2

1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 5 5

4 4 4 4 4 4 4 4 4 4 0 0 0 0 0 1

Number of page fault = 11

LRU example 2 :

Q8: Consider the following page reference using three

frames.Find the page fault using LRU algorithm .

8,8,1,0,5,1,2,3,5,1,4,3,2

8 8 8 8 5 5 5 3 3 3 4 4 4

1 1 1 1 1 1 5 5 5 3 3

0 0 0 2 2 2 1 1 1 2

Number of page fault = 11

1 2 X 3 4 X X 5 X X 6 7 X X 8 X X 9 10 11

1 X 2 3 4 X 5 6 7 8 9 10 11

Page 34: Ch1: Explain how operating system works as a Resource

OPTIMAL example :

Q9: Consider the following page reference using three

frames.Find the page fault using OPTIMAL algorithm .

8,8,1,0,5,1,2,3,5,1,4,3,2

8 8 8 8 5 5 5 4 2

1 1 1 1 1 1 1

0 0 2 3 3 3

Number of page fault = 8

1 X 2 3 4 5 6 7 8