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

Class Notes Updated

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

# Batch Name : PreCAT OM26

# Subject Name : Operating System Concepts

# Section-B (Total 50 Questions) : 9 Questions


- Mostly All questions are concept oriented => 99.99%
no practical/programming/numerical questions => 0.01%
==================================================

# DAY-01:
Q. Why there is need of an OS?

What is a Computer?
- Computer is a machine/hardware/digital device does different tasks
efficiently and accurately for user.
- Computer Hardware System mainly contains:
Processor/CPU
Memory Devices
I/O Devices (Input Output Devices – Keyboard, Monitor)

- there are 4 basic functions of computer:


1. data storage
2. data processing
3. data movement
4. control

- as any user cannot interacts directly with computer hardware, so there is a


need of some inteface between user and hardware, and to provide this
interface is the job of an OS.

Q. What is a software?
- collection of programs

What is a Process?
- program in execution is called as a process
- running program is called as a process
- running instance of a program is called as a process
- program is a passive entity, whereas process is an active entity

Q. What is a Program?
- Program is a finite set of instructions written in any programming language
(i.e. low level / high level) given to the machine to do specific task.
- there are 3 types of programs:
1. system programs : programs which are the part of an OS i.e. inbuilt
programs of an OS.
e.g. kernel, scheduler, memory manager, device driver, loader, dispatcher
etc.....
2. application programs : programs which either comes with an OS or can be
installed later.
e.g. notepad, google chrome, MS Office, fire fox, games, calculator etc...

3. user programs : programs are defined by the programmer user


e.g. main.c, linkedlist.c, addition.cpp, hello.java etc...

- as any user canot directly interacts with an OS, an OS provides two types of
interface for the user in the form of an application programs:
1. CUI/CLI : Command User Interface/Command Line Interface
- by using this kind of interface user can interacts with an OS by means
entering commands onto the terminal/command line in a text format.
e.g. In Windows name of the program which provide CUI => cmd.exe
command prompt
In Linux name of an application program which provides CUI =>
shell/terminal
In MSDOS name of the program which provides CUI => command.com
(MicroSoft Disk Operating System).

Command to compile a program:


$gcc program.c
command to execute program:
$.\a.exe
$./program.out

cls => to clear screen


cp => copy

2. GUI : Graphical User Interface


- by using this kind of interface user can interacts with an OS by means
making an events like click on buttons, left click/rigyht click/double click,
menu bar, menu list etc.....
- Windows = User freindly GUI.
e.g. In Windows name of an application program which provides GUI =>
explorer.exe
In Linux name of an application program which provides GUI =>
GNOME/KDE (GNU Network Object Model Environment / Common Desktop
Environment).

C Programming:

Program.c => compile


[ Source Code Editor ]
Notepad/VS Code Editor/vi editor

Q. What is an OS?
- An OS is a system software ( i.e. collection of system programs ) which acts
an interface between user and hardware.
- An OS also acts as an interface between programs (user programs &
application programs) and hardware.
- As an OS allocates required resources like main memory, CPU time, IO
devices access etc... to all running programs, it is also called as a resource
allocator.
- As an OS manages limited available resources among all running programs,
it is also called as a resource manager.
- An OS not only controls an execution of all programs, it also controls
hardware devices which are connected to the computer system, and hence an
OS is also called as a control program.
- An OS is a software (i.e. collection of thousands of system programs and
application programs in a binary format) comes either in a CD/DVD/PD, and
mainly it has 3 components:
1. Kernel = it is a core part/program of an OS which runs continuosly into the
main memory and does basic minimal functionalities (i.e. compulsory
functionalities -> any OS must supports these functionalities) of an OS.
Memory Management
Process Management
CPU Scheduling
Hardware Abstraction
File & IO Management
- An OS = Kernel OR Kernel= OS
- Without Kernel OS is nothing, its like heart of an OS.
- If Kernel gets crashed then there is need to reinstall an OS.
e.g.
In Windows name of kernel program => ntoskrnl.exe
In Linux name of kernel program => vmlinuz

Loader : it is a system program (i.e. inbuilt program of an OS) which laods an


executable file from HDD into the main memory.

Dispatcher : it is a system program (i.e. inbuilt program of an OS)


which loads data and instruction of a program from the main memory onto the
CPU.

Main Memory/RAM => for an execution of any program RAM is must, in


which running programs i.e. processes can be kept temporarily.
HDD => Permanent storage device.

- Computer Memory can be divided into two catagories:


1. primary memory – memory which can be accessible directly by the
processor

2. secondary memory - memory which cannot be accessible directly by the


processor
e.g. HDD
if processor want to access data from HDD, first that gets loaded into the main
memory and then only CPU can have access of that data.

printf( ), scsnf( ) etc.... => lib functions whose declarations are theer in a
header file named as stdio.h
so by means of including header by the prrprocessor only declarations of lib
functions gets included with program, definitions of all lib functions are exists
in a precompiled object module format in a lib folder, which gets linked by the
linker with an object file of your program and it creates final single executable
file.

- task manager – it is an application program which displays information about


running programs in WINDOWS OS.

- if any program wants to completes its execution, then it required main


memory, CPU time, it required i/o devices access ==> resources

# Scenario-1:
Machine-1: Windows => program.c ( c source code)

Machine-2: Linux => program.c => compile + execute => YES

C Portability => program written in C on any machine/platform can be


compile and execute on any other machine/platform with no/very less
changes.

# Scenario-2:
Machine-1: Windows => program.c => compile => program.exe (executable
code)

Machine-2: Linux => program.exe (executable code) => execute => NO


- In Linux OS dot extension doesnt matter
Why ??
file format
- file format of an executable file in Windows is PE (Portable Executable),
whereas file format of an executable file in Linux is ELF (Executable &
Linkable Format).
- file format is a specific way to store data & instructions of a program inside
an executable file, and it is different in diff OS.
- in Linux file format of an executable file is ELF:

- ELF file format divides an executable file logically into sections and inside
each section specific contents can be kept in an organized manner:
1. elf header
2. bss section (block started by symbol)
3. data section
4. rodata (read only data )section
5. code/text section
6. symbol table

//uninitialized global & static vars gets stored into bss section
int g_var;
int static i;

//initialized global & static vars gets stored into data section
int g_var=99;
int static i=999;

rodata section contains constants and string literals


e.g.
10
100L
10.20
11.22f
‘C’

“SunBeam”

# Linker => It is a system program (i.e. inbuilt program of an OS), which links
object file/s created by the compiler and assembler with precompiled object
modules of lib functions and creates final executable code.

Q. What is a Process?
- Process => when a program gets loaded into the main memory it becomes a
process, program in execution is called as a process.
# OS_DAY-02:
- OS is software (i.e. collection of thousands of system programs and
application programs in a binary format) comes with either in a CD/DVD/PD.
- to install an OS onto the computer system
- to install an OS software onto the computer is nothing but to store OS
software (i.e. collection of thousands of system programs and application
program which are in a binary format) onto the HDD.
- if any OS wants to becomes active, atleast its core program i.e. kernel must
be loaded into the main memory from HDD, and process to load kernel from
HDD into the main memory is called as a booting and this is done by one
special program named as bootstrap program.

Bootable device => if any storage device contains one special program called
as bootstrap program in its first sector i.e. in first 512 bytes then it is referred
as bootable device.
e.g. Pen Drive
- Usually the size of 1 sector = 512 bytes.

If any PD contains one special program called as bootstrap program in its first
sector i.e. in first 512 bytes then it is referred as bootbale PD, otherwise it is
referred as non-bootable.
CD
DVD
PD
HDD

- there are two steps of booting:


1. machine boot/hardware booting
step-1: when we switch on power supply, current gets passed to the
motherboard onto which inside ROM memory there is one micro-program
named as BIOS (Basic Input Output System) gets executes first.

step-2 : first step/job of BIOS is POST (Power On Self Test), under POST it
checks wheather all peripheral devices are connected properly or not and
there working status.

step-3 : after POST, BIOS invokes bootstrap loader program, which searches
for available bootable devices in a system and at a time it selects only one
bootable device out of them as per thr priority decided in a BIOS settings.
(by default any system contains one bootable device i.e. HDD).

System Boot:

Step-4 : after selection of bootable device (as a HDD), bootloader program in


it gets executes, which displays list of names of an OS’s installed onto that
machine from which user has to select any one OS.
step-5: upon selection of any one OS, bootstrap program of that OS gets
executes and it locates the kernel into the HDD and load it into the main
memory.

peripheral devices : devices which are connected to the motherboard


externally referred as peripheral devices/peripheral.

- We can have more than one OS’s installed on one machine i.e. onto the HDD
at a time, and to do this we need to divide HDD logically into partitions and on
each paritition one OS can be install.
- At a time only one OS can be in a active state.

Windows
Linux – ubuntu/redhad/kalo/centos distros of Linux
UNIX
MAC OS X => MAC Machines
iOS - iPhone/iPod
Android - mobiles
Solaris
Windows Server
MSDOS
Symbian => Nokia Mobile
etc.....

- thousands of OS’s are available into the market


- we will learn system arch design of UNIX system

UNIX :
Q. Why UNIX?
System Archtecture Design of UNIX
- Linux & UNIX are two different OS
- Linux is UNIX like OS, which was developed by Linus Torvald as his
academic project in the decade 1990’s by getting inspired from UNIX , and in
1991 first linux kernel version 0.01 was released.

- Linux is an open source OS, i.e. source code of Linux Kernel i.e. vmlinuz is
freely available onto the internet, so anyone can download linux kernel and
see source code.
- Windows/UNIX are commercial OS, i.e. we need to pay if we want to use.
- Android is a Linux based OS.
# System Arch Design of UNIX:
- as any user program cannot directly interacts/communicates with computer
hardware, hence an kernel i.e. core part/program of an OS acts as an
interface beteween user programs and hardware.

- motherboard is a hardware in computer h/w system.


- kernel is a core program(very very imp program of any OS)/part of an OS.

Human Body System : it is made of diff subssystems


- digestive system
- respiratory system
- reproduction system
- nervous system
- excretory system
- circulatory system
etc...

- all subsystems in a human body system works to gether for whole


functioning of human body, simillary in any OS there are diff subsystems
works together for functionning of whole OS.

- file subsystem
- process control subsystem : ipc, cpu scheduling, memory managment
- system call interface block
- device drivers
- buffer cache
- hardwar abstraction block

- out of these all subsystem, there are 2 major subsystems:


1. file subsystem
2. process control subsystem

- In UNIX, whatever that can be stored is considered as a file and whatever is


in active state is referred as a process.
- UNIX treats all devices as a file
- In devices can be catagorised into two catagories:
1. character devices : devices from which data gets transfers char by char
considered as character devices i.e. character special device files.
e.g. keyboard, monitor, printer etc....
sizeof 1 char = 1 byte

2. block devices : devices from which data gets transfers bock by block i..e
sector by sector considered as block devices i.e. block special special device
files.
Usually the size of 1 sector = 512 bytes
e.g. all storage devices
- when we copy data from HDD to PD i.e. an OS copies data from one block
special device into another block special device file i.e. it is a copying of data
from one file to another file.

- In UNIX ==> file has space and process has life.

- Human Body – Soul => Dead Body => Passive Entity


- Human Body + Soul => Living Human Being => Active Entity

- Program HDD => Program


- Program gets loaded into the RAM => Process

from user point of view => Keyboard => h/w device => char special device
file
from user point of view => Monitor => h/w device => char special device file

from user point of view => HDD => h/w device i.e. memory device => block
special device file

buffer cache => it is purely software technique in which portion of main


memory will be used by the kernel to keep most recently accessed disk
contents temporarily to speed up data accessing from HDD.

Cache Memory => it is a hardware/memory device used to reduce speed


mismatch between the CPU and main memory.

Linked List:
Program => slll.c
main( ) => client function

services => server functions: which provides specific service


-------------------------------------
create_node( )
add_at_last( )
add_at_first( )
add_at_pos( )
delete_last( )
.
.
.
Kernel => Program
functions => system calls

- System Calls : are nothing but functions of kernel program defined in C, C++
& assembly language, which provides interface of the services made available
by the kernel for users.
i.e. in other words, if any programmer user want to use services made
available by the kernel in his/her program then either these services can be
used directly (by using system call programming) by means of giving call to
system calls or indirectly system calls can be called from set of library
functions.

kernel services => memory management, file and io management, process


management etc.....

e.g.
to open a file/to create a new file => fopen( ) => open( ) system call
to close a file => fclose( ) => close( ) sys call
to write data into the file => printf( )/ fprintf( )/ fwrite( )/fputc( )/fputs( ) =>
write( ) system call
to read data from file => scanf()/fscanf()/fread()/fgets()/fgetc( ) => read()
system call

- to create a new process => fork( )


- to terminate/exit process => _exit( )
- to suspend process

- exit( ) is a c lib function which internally makes call to _exit( ) system call
due to which process gets terminated.

- In UNIX there are 64 system calls


- In Linux there are more than 300 system calls
- In Windows more than 3000 system call are there.

- In UNIX name of system call use to create a new process/child process =>
fork( ).
- In Linux name of system call use to create a new process/child process =>
clone() / fork( )
- In Windows name of system call use to create a new process/child process
=> CreateProcess( ).
irrespective of an OS, there are 6 catagories of system calls:
1. process control system calls: e.g. fork( ), wait( ), _exit( ) etc....

2. file operations system calls : e.g. open( ), close( ), read( ), write( ), lseek( )
etc...

3. device control system calls : e.g. open( ), close( ), read( ), write( ), ioctl()
etc....

4. accounting information system calls : e.g. getpid( ), getppid( )


getpid( ) sys call is used to get PID (unique identfier) of calling process
getppid( ) sys call is used to get PID of parent process of calling process

5. protection and security system calls : e.g. chmod( ), chown( )


chmod( ) sys call is used to change access perms of a file
chown( ) sys call is used to change owner of a file
etc...

6. inter process communication system calls : pipe( ), signal( ) etc...

- An OS identifies each process uniquely by its PID (Process ID).


- lseek() sys call gets called internally from fseek() lib function to set file
cursor at specific position.
- ioctl( ) - i/o device control system call
//program to do addition of two numbers: user defined code
#include<stdio.h>

int main(void)
{
int n1, n2, res;

printf(“enter the value of n1 & n2 : “ );//=> write( ) sys call


scanf(“%d %d”, &n1, &n2);//read( ) sys call

res = n1 + n2;

printf(“res = %d\n”, res);//write( ) sys call

return 0;//successfull termination


}

write( ) sys call => function of kernel program => it is a part of system
defined code => whenever system call gets called, the CPU switches from
user defined code into system defined code, hence system calls are also called
as software interrupts/trap.

Q. What is an interrupt ?
- an interrupt is a signal recieved by the CPU from any io device due to which
it stops an execution of one process and start executing another process.
- interrupts sent by an io devices to the CPU are called as hardware
interrupts.

- throughout an execution of any program the CPU keep sswitches in between


user defined code and system defined code, and this mode of operation is
called as dual mode operation.
- system runs in 2 modes:
1. user mode – if the CPU executes user defined code instructions we can say
system runs in a user mode.

2. system mode / kernel mode - if the CPU executes system defined code
instructions we can say system runs in a system mode/kernel mode.

- how the CPU comes to know that currenly executing instruction is of user
definded code or system defined code, to diferentiate between user mode and
kernel mode there is one bit onto the CPU called as mode bit whose value will
be maintained by an OS.
- user mode => mode bit = 1
- system mode => mode bit = 0

system code => system programs: kernel functions


- process & file are two very very important concepts in any OS.
- to learn an OS is nothing but to learn 2 major subsystems of it
1. process control subsystem
2. file subsystem

# Process Management:
- When we say an OS does process management, it means an OS is responsible
for process creation, to allocate resources for it, cpu scheduling, process
synchronization, inter process communiation and to terminate process as well
is OS is responsible.

# OS DAY-04:
- name of the Windows Kernel =>
ntoskrnl.exe
win32krnl.exe

linker => it is a system program which links object file/s created by the
compiler and assembler with precompiled object modules of lib functions and
creates final single executable code.

As an OS dont want to keep CPU idle, hence in the following 4 cases CPU
scheduler must be callled:
case-1: running state => terminated : due to an exit
case-2: running state => waiting : due to an io request

case-3: running state => ready : due to an interrupt


case-4: waiting state => ready : due to an io request completion.

- there are two types of cpu scheduling:


1. non-preemptive:
under this type of cpu scheduling control of the CPU released by the process
by its own i.e. voluntarily.
e.g. above case-1 & case-2

2. preemptive :
under this type of CPU scheduling control of the CPU taken away forcefully
from a process i.e. process gets suspended and control of the CPU can be
given to the scheduled process.
case-3 & case-4
- there are basic 4 cpu scheduling algorithms:
1. fcfs cpu scheduling
2. sjf cpu scheduling
3. round robin cpu scheduling
4. priority cpu scheduling

- multiple cpu scheduling algorithms are there, hence there is a need to decide
which algo is best suited at which situation and which algo is an efficient one,
to decide this there are certain criterias referred as cpu scheduling criterias:

1. cpu utilization : one need to select such an algo in which utilization of the
CPU must be as max as possible.

2. throughput : total work done per unit time


one need to select such an algo in which throughput must be as max as
possible.

3. waiting time : it is the total amount of time spent by the process into the
ready queue for waiting to get control of the CPU from its time of submission.
- one need to select such an algo in which waiting time must be as min as
possible.

4. response time : it is time required for the process to get first response from
the CPU from its time of submission.
- one need to select such an algo in which response time must be as min as
possible.

5. turn-around-time : it is the total amount of time required for the process to


complete its execution from its time of submission.
- one need to select such an algo in which turn-around-time must be as min as
possible.

Turn-aroun-time = waiting time + execution time

- turna-round-time = total amount of time spent by the process into the ready
queue for waiting and onto the CPU for execution.

Execution time : it is the amount of time spent by the process onto the CPU to
complete its execution.
CPU burst time : total no. of cpu cycles required for a process to complete its
execution.
1. fcfs (first come first served) cpu scheduling algorithm:
- in this algo, whichever process arrived first into the ready queue gets control
of the CPU first i.e. control of the CPU gets allocated for process as per their
order of arrivale into the ready queue.
- this algo is simple to implement and can be implemented by using fifo queue.

Gant chart => it is a bar chart representation of allocation of the CPU for
processes in terms CPU cycle numbers.
- in fcfs algo, due to an arrival of longer process before shorter processes,
shorter proceses has to wait for longer duration, due to which average waiting
time gets increases which results into increase in average turn-around-time,
and overall system performance gets down, this effect is referred as convoy
effect.

- to avoid convoy effect, sjf cpu scheduling has been designed.

2. sjf (shortest job first) cpu scheduling algorithm


- in this also, process which is having min CPU burst time gets control of the
CPU first.
- in sjf, tie can be resolved by using fcfs.

- if arrival time/submission time of proceses is not same, then sjf (non-


preemptive) fails, and hence there are two types of sjf:
1. non-preemptive sjf (shortest-next-time-first): which fails of arrival time of
process is different

2. preemptive sjf : (shortest-remaining-time-first), this algo works even if


aarival time of processes are different.
starvation:
- in sjf (either preemptive/non-preemptive) => out of processes which are in a
ready queue process which is having min cpu burst time gets control of the
cpu first i.e. shortest process has got highest priority

=> ready queue => 100 jobs (P1 – largest job)

=> in a multi-programming system at a time multiple processes can be


submitted and can keep on submitting during runtime as well
ready queue => 100 jobs (P1 – largest job)
processes which are getting submitted into the system during runtime also
has cpu burst time less that cpu burst of P1, in such case process P1 which is
having larger cpu burst time may gets blocked into the ready queue, this
situation is called as starvation/indefinite blocking.
- to overcome problem of starvation in sjf, round robin algo has been designed.

# OS DAY-05:

- to avoid the problem of starvation in sjf, round robin algo has been designed.

Processes/Jobs Priority Value CPU Burst Time


P1 5 10
P2 3 12
P3 1 9
P4 4 7
P5 2 11

P3 -> P5 -> P2 -> P4 -> P1


ready queue => 100 jobs are there : P1 – lowest priority

multi-programming system => during runtime multiple processes can be


submitted at a time and during runtime as well processes are keep on
submitting into the system

process P1 may gets blocked into the ready queue => starvation

IPC:
Q. Why there is need of an IPC?

Q. What is an IPC?
- any process cannot directly communicates with any other process, there is a
need of some medium, and to provide this meduim for inter process
communication is the job of an OS.

- further there 4 ipc techniques under message passing model:


1. pipe

pipe has two ends


one end => inlet
second end => outlet

pipe object (temp buffer in the main memory) provides by an OS in which one
process can write data into it from one end, where second process can read
data from pipe object from another end, so at a time one process can send
message to another process, vice-versa is not possible.

- processes which are running in a system can be catagorised into two more
catagories:
1. related processes : processes which are of same parent
2. non-related processes : processes which are of different parents

# way-1 : text message => text data


# way-2 : voice call => voice data
# way-3 : video call => voice data + video data
# way-4 : missed calls
signal
1 missed call ==> predefined meaning
2 missed calls ==> predefined meaning
3 missed calls ==> predefined meaning

SIGSEGV = termination of a program due segment violation


- if any process trying access memory which is not allocated for it then an OS
sends SIGSEGV signal due which process gets terminated by printing message
as segmentation fault.

A
B
C
On One Desk => One NoteBook
if i ask to all of them to write something on same notebook, on same page
and on same line at a time ===> race condition

NoteBook => Page => Line => DBDA


A
B
C

data inconsistency

race condition – if two or more processes are trying to access single resource
at a time then race condition occurs.
- to avoid race condition, and OS has to first
- decide order of allocation of resource for processes

- to avoid problem of data inconsistency in critical section problem, an OS uses


two synchronization tools:
1. semaphore:
2. mutex
# OS DAY-06:
- there are two synchronization tools:
1. semaphore:
- there are two types of semaphore:
i. binary semaphore
ii. classic semaphore/counting semaphore:
- this synchronization tool is used when resource can be acquired by more
than one processes at a time.
- classic semaphore/counting semaphore simply a counter variable.

2. mutex object
- binary semaphore & mutex object is used when resource can be acquired by
only one process.

Covid = Goverment

1. prevention:
use of mask
social distancing
washing hands regularly by water/sanitizer
lockdown
vaccination

2. detection & avoidance:

3. recovery :
hospitalized => treatment

- an OS handles deadlock siutuation by 3 ways/there are 3 deadlock handling


methods used in an OS:
1. deadlock prevention:
deadlock can be prevented by discarding any one cond out of 4 necc & suff
conditions.
2. deadlock detection & avoidance :
before allocating resources for processes in advanced all the input can be
given to deadlock detection algorithms, and it gets checked wheather there
are chances to occur deadlock or not, if there are chances to occur deadlock
then necc changes can be done, and deadlock can be avoided.
- there are two deadlock detection & avoidance algorithms:
1. resource allocation graph algorithm
2. banker’s algorithm

3. deadlock recovery : system can recovered from deadlock by two ways:


i. process termination :

ii. resource preemption:

# Memory Management:
- when we say an OS does memory management, it manages main memory.

Q. Why there is a need of memory (main memory) management?


size of main memory = 4 GB/8 GB/16 GB/32 GB
size of secondary storage = 500 GB/ 1 TB/2 TB
main memory is a limited memory

- for an execution of any program it must be loaded into the RAM, and hence
RAM is also called as main memory.

=> max CPU utilization


=> multi-tasking/time sharing
=> multi-programming : system in which multiple processes can be submitted
into at a time.
=> if an OS is supporting multi-programming i.e. if multiple processes gets
submitted into the system at a time whereas main memory is limited, so it is
responsibility of an OS to complete an execution of all submitted processes.
SunBeam Hinjwadi => Biggest Lecture Hall => Krishna Hall => “225”
physical seat numbers : 1 to 225

- Website PreCAT of 1 month from 1st Jan to 31st Jan 2022 of capacity 1000 will
be starting and admissions are open.
YES
registrations by paying fees => 1 to 1000 => logical seat numbers
20th dec all admission are full

- in each batch first 25 seats are reserved for faculties


- we need to divide batch of 1000 students into 5 equal size sub batches
batch-1 : 1 to 200 : 6 TO 8
batch-2 : 201 to 400 : 8 TO 10
batch-3 : 401 to 600 : 10 TO 12
batch-4 : 601 to 800 : 12 TO 2
batch-5 : 801 to 1000 : 2 TO 4

On 1st Jan =>


batch-1 => 1 -> 26, 2 -> 27, 3 -> 28, .............., 200 -> 225
batch-2 => 201 -> 26, 202 -> 27, ...................., 400 -> 225
batch-3 =>
batch-4 =>
batch-5 =>

2nd Jan =>

PG – Rooms: Sahyadri => PG

Swap Area : it is a portion of HDD kept reserved at the time installation an


Osm which can be used by an OS as an extension of the main memory to keep
inactive running programs.
- When any process is requesting for the memory, there are two methods by
which memory gets allocated for it referred memory allocation methods:
1. contiguos memory allocation
2. non-contiguos memory allocation

1. contiguos memory allocation:


under this type of memory allocation method, process can completes its
execution only if memory gets allocated for it in a contiguos manner.
- there are 2 memory allocation schemes under contiguos allocation:
i. fixed size partitioning scheme

- an OS maintains linked list of free partitions, and when any process is


requesting for the memory, it referes the linked list of free partitions and uses
any one algorithm out of 3 below mentioned algorithms:
1. first fit : linked list of free partitions will be traversed, and whichever first
free partition in which process can fit will allocated for process.
- it is faster allocation method.

2. worst fit : such a largest free partition gets allocated for a process due to
which there is more internal fragmentation.

3. best fit : such a smallest free partition in which process can fit gets
allocated for a process so that there is very less internal fragmentation.
- there is less memory wastage.

combination first fit and best fit is mostly implemented.

# OS DAY-07:
Main Memory = 4 GB (1 GB – Kernel + 3 GB User Space ).
Swap Area = 8 GB

Virtual Memory = 4 GB + 8 GB = 12 GB.

is is possible for an OS to complete an execution of such a process which is


having size bigger than size of main memory itself ?? ==> YES
P1 = 6 GB

# Virtual Memory Management :


- in this technique, an OS not only manages physical memory (i.e. main
memory), it also manages virtual memory (i.e. memory which is not a part of
main memory / which is not physical memory ==> swap area).
Virtual Memory Management = Paging + Swapping
- Big size process gets divided into pages, and not all pages of that process
gets loaded into the main memory at once, few pages of that process gets
loaded into the main memory whereas few pages can be kept temporarily into
swap area i.e. only active pages can be loaded into the main memory and
inactive pages can be kept temporarily into the swap area.
- if a process is requesting for any page and that requested page is not exists
into the main memory it is a referred as page fault, and when page fault
occurs, requested page can be swapped in into the main memory from swap
area, i.e. page of any process will be loaded into the main memory only after
requesting/demanding it by the process, hence it is referred as demand
paging, in virtual memory management memory manager is also referred as
lazy swapper.

- In a multi-programming system more than one processes can be submitted at


a time, and if out them one process is having size bigger than size of main
memory itself, in this case no. of pages >>>>> no. of frames
and there quite good chances frequently all frames becomes full, and in this
situation if page fault occurs, so there is need to load requested page from
swap area into the main memory, but as there is no free frame available, so
there is need to remove any one existing page from the main memory and can
kept temporarily into the swap area i.e. there is need of page replacement,
and to do this there are certain algorithms called as page replacement
algorithms:
- there 5 page replacement algorithms:
1. fifo (first in first out) page replacement algorithm
- in this algo, page which was inserted first into the main memory will be
removed first and requested page will be loaded into that free frame
i.e. page which was inserted first will replaced first.

2. optimal page replacement algorithm:


- in this algo page which will not get use in near future will be replaced.
As it is not feasible practically, hence this algo is used only to set bechmark
for other algorithms.

3. lru (least recently used) page replacement algorithm:


- in this algo least recently used page will be replaced.

4. lfu (least frequently used) page replacement algorithm:


- in this algo least frequently used page will be replaced.

5. mfu (most frequently used) page replacement algorithm:


- in this algo most frequently used page will be replaced.

Thrashing:
If a process spent more time on paging rather than executing it, this high
paging activity is referred as a thrashing.
# File Management:
What is a file ?
user point of view:
- file is a named collection of logically related data or information
- file is a basic storage unit
- file is a like a container which contains logically related
data/information/records.

system point view:


- file is a stream of bits/bytes

file has 2 things:


1. data : actual file contents which are inside the file
2. metadata : information about the file like name, size, parent folder location,
time stamps, access perms etc... can be kept inside one structure named as
FCB, in UNIX also called as iNode.

Process => PCB (Process Control Block)


File => FCB (File Control Block)

- FCB/iNode contains information about file


- iNode number – unique identfier of a file
- name of the file
- type of the file
- size of the file
- access perms
- time stamps
etc....

- When any new file gets created one structure gets created for that file
no. of iNodes = no. of files
- data & metadata of all files can be kept permanently onto the HDD i.e.
if 10k files are there, 10k iNodes are there onto the disk, and millions of bytes
of data of 10 k files is also kept onto the disk.

Filesystem => it is a way to store data onto the disk (onto any storage device)
in an organized manner so that it can be accessed efficiently.
- way of storing data onto the disk in an organized manner is vary from OS to
OS, hence each OS supports its own filesystem.
e.g.
Windows => FAT16/FAT32 (File Allocation Table), NTFS (New Technology
FileSystem).
Linux => ext2/ext3/ext4 (Extended FileSystem)
UNIX => UFS UNIX FileSystem
MAC OS => HFS : Hierarchical File System
CDFS =>
etc....

- to format any storage device is not always to erase data from it, it is nothing
but to create a new filesystem on it, and while creating a new filesystem on it
data may/may or not gets erased from it, and hence even after formatting
HDD we can recover data by using some data recovery tools if it has not
erased.
- filesystem divides storage device logically into sectors/blocks, and inside
each block/sector specific contents can be kept.

PD => 4 GB => when we format a PD new filesystem gets created on it

free space ~= 3.8 GB


4 – 3.8 = filesystem infomation

- When any file is requesting for free data blocks, there are 3 methods by
which free data blocks gets allocated for it, these methods are called as disk
space allocation methods:

1. contiguos allocation method:


- in this method, when any file is requesting for free data blocks, then free
data blocks gets allocated for that file only in a contoguos manner, and an
addr of starting data block and count i.e. no. of data blocks allocated for can
be kept inside iNode of that file.

2. linked list allocation method:


- in this method, when any file is requesting for free data blocks, then
randomly any free data blocks gets allocated for that file, whereas linked list
of those allocated data blocks will be maintained in such a way that each data
block contains actual data as well as an addr of its next data block, and an ddr
of starting data block and end data block in that linked list can be kept inside
iNode of that file.

3. index allocation method:


- in this method, when any file is requesting for free data blocks, then
randomly any free data blocks gets allocated for that file, and any one data
block out will be considered as an index data block in wihch an addresses of
remaining data blocks can be kept, wheras an addr of index data block will be
inside an iNode of that file.
HDD:
- Storage device
- Each and every device has its own dedicated processor called as controller
which controls all its operations.
e.g. HDD has its own processor called as disk controller (h/w unit) which
controls all disk operations like movement of the head for writing & reading
operations.
- head (h/w) is conducting coil in a hdd which performs write & read operation
by means of writing and reading data into/from one sector at a time
i.e. head has capacity to read/write 512 bytes of data at a time.
- and to control head movement is the job disk controller, and at a time disk
controller can accept and complete only one request.

In a multi-programming system 100’s of processes are running at a time, and


there are quite good chances that out of 100’s processes, more than one
processes can make a request to access data from hdd at a time, and in this
case all requests can be kept into waiting queue of hdd, and as disk controller
can accept and complete only one request at a time, only request can be sent
to the disk controller and hence there is need of scheduling that request, and
to do this there are certain algorithms referred as disk scheduling algorithms:
- there are 5 disk scheduling algorithms:
1. fcfs (first come first served) disk scheduling algorithm
2. sstf (shortest seek time first) disk scheduling algorithm
3. scan disk scheduling algorithm
4. c-scan disk scheduling algorithm
3.look disk scheduling algorithm

seek time : it is the total amount of time required for the disk controller to
move head from its cur position to desired sector.

CCAT - OS
Min : Lecture Notes + PPTs + Black Book + First 2 chapters of Galvin Book.
Max : Galvin + Goole

You might also like