Class Notes Updated
Class Notes Updated
Class Notes Updated
# 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)
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...
- 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).
C Programming:
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
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.
# Scenario-1:
Machine-1: Windows => program.c ( c source code)
# Scenario-2:
Machine-1: Windows => program.c => compile => program.exe (executable
code)
- 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;
“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
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:
- 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.....
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.
- file subsystem
- process control subsystem : ipc, cpu scheduling, memory managment
- system call interface block
- device drivers
- buffer cache
- hardwar abstraction block
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.
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
Linked List:
Program => slll.c
main( ) => client function
- 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.
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
- exit( ) is a c lib function which internally makes call to _exit( ) system call
due to which process gets terminated.
- 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....
int main(void)
{
int n1, n2, res;
res = n1 + n2;
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.
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
# 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
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.
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.
- 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.
# OS DAY-05:
- to avoid the problem of starvation in sjf, round robin algo has been designed.
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.
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
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
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
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
3. recovery :
hospitalized => treatment
# Memory Management:
- when we say an OS does memory management, it manages main memory.
- for an execution of any program it must be loaded into the RAM, and hence
RAM is also called as main memory.
- 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
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.
# OS DAY-07:
Main Memory = 4 GB (1 GB – Kernel + 3 GB User Space ).
Swap Area = 8 GB
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.
- 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.
- 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:
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