Operating System

Operating System Full Notes

Operating System

➤ Software abstracting hardware

 Interface between user and hardware

 Set of utilities to simplify application development/execution

 Control program

 Acts like a government

Services of Operating System

 User Interface

 Program Execution

 Input/Output Operation

 File-System manipulation

 Communication (inter-process communication)

 Error Detection

 Resource Allocation

 Accounting

 Protection & Security

Goals of Operating System

 Convenience (User-friendly)

 Efficiency

 Portability

 Reliability

 Scalability

 Robustness

Parts of Operating System

(i) Kernel

(ii) Shell

Parts of Shell

(i) CLI (Command Line interface)

(ii) GUI (Graphical user interface)

System Call

A system call is a way for programs to interact with the operating system

Dual Mode of Operation

 User Mode (mode bit=1)

 Kernel/System/Supervisor/Privileged Mode (mode bit=0)

Type of Operating Systems

1. Uni-programming OS

2. Multi-programming OS

3. Multi-Tasking OS

4. Multi-User OS

5. Multi-Processing OS

6. Embedded OS

7. Real-Time OS

8. Hand-held Device OS

Uni-programming OS

OS allows only one process to reside in main memory

 Single process can not keep CPU & I/O Devices busy simultaneously

 Not a good CPU utilization

Multi-programming OS

OS allows multiple processes to reside in main memory

 Better CPU utilization than uni-programming

Type of Multi-programming OS

(i) Preemptive

    A process can be forcefully taken out of CPU.

(ii) Non-preemptive

    A process runs of CPU till its wish.

    Either process terminates

    or process goes for I/O operation

Multi-tasking OS/Time Sharing OS

Extension of multi-programming OS in which process execute in round-robin fashion.

Multi-User OS

This OS allows multiple users to access single system simultaneously

 Windows is not multi-user OS

 Unix & Linux is multi-user OS

Multi-Processing OS

This OS is used in Computer system with multiple CPUs

Type of Multi-processing OS

(i) Tightly Coupled (Shared Memory)

(ii) Loosely Coupled (Distributed System)

Embedded OS

An OS for embedded computer systems.

 Designed for a specific purpose, to increase functionality and reliability for achieving a specific task.

Real-Time OS

Real time operating systems (RTOS) are used in environments where a large number of events, mostly external to the computer system, must be accepted and processed in a short time or within certain deadlines.

 OS used for rocket launching

 Every process has a deadline

Type of Real-Time OS

(i) Hard RTOS

    Strict about deadlines

(ii) Soft RTOS

    Some relaxation in deadline

Hand-held Device OS

OS used in hand-held devices.

Process

program under execution

process=program+runtime activity
                                            
                (code)                operands & other
                                             information
                instruction

Process

➤ Program under execution

➤ An instance of program

➤ Schedulable/Dispatchable unit (CPU)

➤ Unit of execution (CPU)

➤ Locus of control (OS)

Process as Data Structure

Process as Data Structure


Representation of a Process
Representation of a Process

Operation on a Process
➤ Create (Resource Allocation)
➤ Schedule, Run
➤ Wait/Block
➤ Suspend, Resume
➤ Terminate (Resource Deallocation)

Attributes of a Process

➤ PID

➤ PC

➤ GPR

➤ List of Devices

➤ Type

➤ Size

➤ Memory Limits

➤ Priority

➤ State

➤ List of Files

PCB (Process Control Block)

➤ Also known as process descriptor

PCB (Process Control Block)

Context

The content of PCB of a process are collectively know as 'Context' of that process

➤ Context save

➤ Context load

➤ stop a running process & run another process

Question 1

While running a process can access its PCB from main memory? True/False

Ans- False

Question 2

A process in the context of computing is:

a) A set of instructions to be executed on a computer

b) A program in execution

c) A piece of hardware that executes a set of instructions

d) The main procedure of a program

Ans- A program in execution (b)

Question 3

Which technique was intoduced because a single job could not keep both CPU and IO devices busy?

a) Real Time

b) Spooling

c) Preemptive Scheduling

d) Multi programming

Ans- Multi programming (d)

Process States

Process States


New:- All installed processes are in known to be in new state

Ready:- All processes which are waiting to run on CPU are known to be in ready satate

Running:- A process which is running on CPU its state as running

Terminated:- A completed process has its state as terminated

Blocked/Waiting:- All processes which are waiting for any IO or event

Process States Transitions

New To Ready: When process is admitted by OS

Ready to Running: When a process is dispatched to CPU

Running to Terminated: When a process goes for IO event

Running to Ready: When a Process is preempted

Blocked to Ready: When a process completes IO event

Process States Transitions

2 Transitions are voluntary:

➤ Running to Terminated

➤ Running to Blocked

CPU vs IO Bound Process

CPU Bound: If the process is intensive in terms of CPU operations

IO Bound: If the process is intensive terms of IO operations

Question 1

Which of the following state is/are initiated by process itself?

a) Running

b) Ready

c) Terminated

d) Blocked

Ans- Terminated,Blocked (c,d)

Question 2

A process which has just terminated but has to relinquish its resources is called?

a) Suspended Process

b) Zombie Process

c) blocked Process

d) Terminate Process

Ans- Zombie Process (b)

Process Scheduling

➤ Needed because?

                        better resource utilization

Scheduling Queues

➤ Job Queue: All processes which are in new state

➤ Ready Queue: All processes which are in ready state

➤ Device Queue: All processes which are waiting for a specific device

cheduling Queues

Type of Schedulers

1. Long-Term Scheduler (Job)

2. Short-Term Scheduler (CPU)

3. Mid-Term Scheduler (Medium-term)

Updated Process States

Process States

CPU Scheduling

Function:

    ➤ Make a selection

Goal

    ➤ Minimize Wait time and Turn-around time

    ➤ Maximize CPU utilization (Throughput)

    ➤ Fairness

Note:-  Long-term scheduler controls max degree of multi-programming

Note:- Mid-term scheduler reduces the degree of multi-programming

Question 1

Which of the following scheduler reduces the degree of multi-programming?

a) Short-Term

b) Long-Term

c) Mid-Term

d) Long-Term and Mid-Term both

Ans- Mid-Term (c)

Scheduling Times

1. Arrival Time (AT):- The time at which the process arrives in the system.

2. Burst Time (BT):- The amount of time for which process runs on CPU

3. Completion Time (CT):- The time at which process completes

4. Turnaround Time (TAT):- Time from arrival to completion

                            [ TAT=CT-AT ]

5. Waiting Time (WT)

                            [ WT=TAT-BT ]

6. Response Time (RT): Amount of time from arrival til first time process gets the CPU.

7. Scheduling Length (L): max(CT)-min(AT)

8. Throughput: no of processes executed per unit of time.

                    Throughput=n/L                    n=no of process

CPU Scheduling: Types

1. Preemptive

2. Non-preemptive

Note:- Every process has no any I/O operation[assumption in all algorithms

FCFS (First Come First Serve)

➤ Criteria: Arrival Time (AT)

    ➣ Tie-breaker: smaller process id first

➤ Type: Non-preemptive

Gantt chart:- (always starts from zero)

FCFS (First Come First Serve)

L=max(CT)-min(AT)=40-0=40

Throughput= no of process/L

                        = 3/40

Note:- for non-preemptive algorithm Response time (RT) of a process=Waiting Time (WT) of process

FCFS (First Come First Serve)

L=21-0=21
Throughput=6/21

Convoy Effect (only in FCFS)

➤ If a large process is scheduled first than it slows down system's performance

SJF (Shortest Job First)

➤ Criteria: Burst time (smallest Burst time process first)

        Tie-breaker: FCFS

➤ Type: non preemptive

SJF (Shortest Job First)
SJF (Shortest Job First)

SRTF (Shortest Remaining Time First)
➤ Criteria: BT
        Tie-breaker: FCFS
➤ Type: Pre-emptive

SRTF (Shortest Remaining Time First)
Problem with SJF & SRTF
1. Starvation
2. No fairness
3. Practical Implementation is not possible

HRRN (Highest Response Ratio Next)

🔘 Objective: Not only favors short jobs byt decteases the WT of longer jobs

🔘 Criteria: Response Ration

            Tie-breaker: BT

🔘 Type: Non Pre-emptive

RR=W+S/S

W= Wait Time

S= Service/Burst Time

HRRN (Highest Response Ratio Next)

Priority Based Scheduling

🔘 Criteria: priority

            Tie-breaker: FCFS

🔘 Type: (i) Non- preemptive

                 (ii) preemptive

Priority

🔘 Static

🔘 Dynamic

Priority Based Scheduling

Working in progress.................................