Operating System Notes
Operating System Notes
Working system
we have to write separate programs
User Applications
if we want to interact with the devices
without operating system.
Operating System
Like we want to access RAM.
We have to write a program for
I/O devices, CPU ,
Printer to print to invoke it. RAM,HARD DISK
No one is authoritative who can manage tasks without O/S.
1. Convenience(windows)
2. Throughput (number of tasks executed per unit of time) (Linux ,
apple Macintosh)
3. Resource governor( sever-- multiple client) Task manager
( speed, memory each task , parallel processing)
4. Process management(CPU scheduling algorithms)
5. Storage management(hard disk, files sysyem, NFS, CNFS)
P1 P2 P3
Multi Programmed OS(RAM) 1 1 1
(Maximum processes in RAM)
Non-preemtive(in case there is I/O operation P4 P5 P6
1 1 1
Required then it goes to the p2 otherwise it completes p1 first .
Reduces idleness RAM
Multitasking/ Time Sharing OS
Preemtive … round robin algorithm.. time quantum for each process.
Increases response time
Distributed OS
Geographically (network oriented) independently work, each have own resources but can
shared files.
Clustered OS
Multiple(thousand of) devices (connected like one network to increase power) like server.
Embedded OS
Fixed functionality oven washing, machine
PROCESS STATES
its just a diagram to make understand users. No actual work in computer
Suspend
ready
READY
NEW Terminated
RUNNING
Suspend Wait/Block
wait RAM
New…Store in SS or on some application chrome laptop
mount OS background processes pop create
CIA
Confidentiality( nobody should beable to read the data)… can prevent from encryption
Cryptograpgy means paln text- cipher text
Symmetric(public key) and Asymmetric ( public and private key)
Integrity( no unauthorized modify )
Availiability( 24/7 data available)
Theft odf service( privacy information)
DOS( prevention of legitimate user) ping of death( server buffer full cant take more
requests)
Domain…> set of access rights.
Threat…> convert to …. Attack..>
Phishing… junk emails(spam)
Trojan horse is not actually virus it’s a destructive program look like application
program.do not replicate… just destructive. backdoor entry
Virus attches to executable files until you open.
Warm subclass of virus… it can go by protocols
Firewall…> front door
Carbros security protocol…(windows)
HBAs (host bus adapter)
A host bus adapter (HBA) is a circuit board or integrated circuit adapter that connects a host system,
such as a server, to a storage or network device.
VMS
VIRTUAL MEMORY BASED
Unix, Ubuntu, MacOS, Windows and all Linux based OS examples of multiuser OS.
Multi-user operating systems were originally used for time-sharing and batch processing
on mainframe computers. These types of systems are still in use today by large
companies, universities, and government agencies, and are usually used in servers, such
as the Ubuntu Server edition (21.04 LTS) or Windows Server 2019.
These servers allow several users to access the operating system, kernel, and hardware at the same time.
Kernel
A multi-user operating system makes use of the Kernel component, which is built in a low-level
language. This component is embedded in the computer system's main memory and may
interact directly with the system's H/W.
Device Handler
Each input and output device needs its device handler. The device handler's primary goal is to
provide all requests from the whole device request queue pool. The device handler operates in
continuous cycle mode, first discarding the I/O request block from the queue side.
Spooler
Spooler stands for 'Simultaneous Peripheral Output on Line'. The Spooler runs all computer
processes and outputs the results at the same time. Spooling is used by a variety of output
devices, including printers.
Distributed System
A distributed system is also known as distributed computing. It is a collection of multiple
components distributed over multiple computers that interact, coordinate, and seem like a
single coherent system to the end-user. With the aid of the network, the end-user would be
able to interact with or operate them.
Time-Sliced Systems
It's a system in which each user's job gets a specific amount of CPU time. In other words, each
work is assigned to a specific time period. These time slices look too small to the user's eyes. An
internal component known as the 'Scheduler' decides to run the next job. This scheduler
determines and executes the job that must perform based on the priority cycle.
Multiprocessor System
Multiple processors are used in this system, which helps to improve overall performance. If one
of the processors in this system fails, the other processor is responsible for completing its
assigned task.
Multi-Tasking
Multi-user operating systems may execute several tasks simultaneously, and several programs
may also execute at the same time.
Background Processing
Background processing is a term that refers to when commands are not processed but rather
executed "in the background". Usually, other programs interact with the system in real-time.
Time-Sharing
A strategy used by multi-user operating systems to operate on several user requests at the
same time by switching between jobs at very short periods of time.
System
The operating system must handle a computer's combination of hardware and software
resources.
Invisibility
Various functions of the multi-user operating system are hidden from users. It is due to factors
such as the OS being instinctive or happening at the lower end, such as disk formatting, etc.
Distributed System
A distributed system is also known as distributed computing. It is a collection of multiple
components distributed over multiple computers that interact, coordinate, and seem like a
single coherent system to the end-user. With the aid of the network, the end-user would be
able to interact with or operate them.
Time-Sliced Systems
It's a system in which each user's job gets a specific amount of CPU time. In other words, each
work is assigned to a specific time period. These time slices look too small to the user's eyes. An
internal component known as the 'Scheduler' decides to run the next job. This scheduler
determines and executes the job that must perform based on the priority cycle.
Multiprocessor System
Multiple processors are used in this system, which helps to improve overall performance. If one
of the processors in this system fails, the other processor is responsible for completing its
assigned task.
1. A multi-user operating system can be used in the printing process to allow multiple users
to access the same printer, which a normal operating system may not do.
2. On a single computer system, several users can access the same copy of a document. For
instance, if a PPT file is kept on one computer, other users can see it on other systems.
3. Multi-user operating systems are very useful in offices and libraries because they can
efficiently handle printing jobs.
4. If one computer fails in its own network system, the entire system does not come to a
halt.
5. The ticket reservation system uses a multi-user operating system.
6. Each user can access the same document on their own computer.
Program
A program is a piece of code which may be a single line or millions of lines. A computer
program is usually written by a computer programmer in a programming language. For
example, here is a simple program written in C programming language −
#include <stdio.h>
int main() {
printf("Hello, World! \n");
return 0;
}
A computer program is a collection of instructions that performs a specific task when executed
by a computer. When we compare a program with a process, we can conclude that a process
is a dynamic instance of a computer program.
A part of a computer program that performs a well-defined task is known as an algorithm. A
collection of computer programs, libraries and related data are referred to as a software.
1 Start
This is the initial state when a process is first started/created.
2 Ready
The process is waiting to be assigned to a processor. Ready processes are waiting to have
the processor allocated to them by the operating system so that they can run. Process may
come into this state after Start state or while running it by but interrupted by the scheduler
to assign CPU to some other process.
3 Running
Once the process has been assigned to a processor by the OS scheduler, the process
state is set to running and the processor executes its instructions.
4 Waiting
Process moves into the waiting state if it needs to wait for a resource, such as waiting for
user input, or waiting for a file to become available.
5 Terminated or Exit
Once the process finishes its execution, or it is terminated by the operating system, it is
moved to the terminated state where it waits to be removed from main memory.
Process Control Block (PCB)
A Process Control Block is a data structure maintained by the Operating System for every
process. The PCB is identified by an integer process ID (PID). A PCB keeps all the information
needed to keep track of a process as listed below in the table −
1 Process State
The current state of the process i.e., whether it is ready, running, waiting, or whatever.
2 Process privileges
This is required to allow/disallow access to system resources.
3 Process ID
Unique identification for each of the process in the operating system.
4 Pointer
A pointer to parent process.
5 Program Counter
Program Counter is a pointer to the address of the next instruction to be executed for this
process.
6 CPU registers
Various CPU registers where process need to be stored for execution for running state.
9 Accounting information
This includes the amount of CPU used for process execution, time limits, execution ID etc.
10 IO status information
This includes a list of I/O devices allocated to the process.
The PCB is maintained for a process throughout its lifetime, and is deleted once the process terminates.
Process scheduling is an essential part of a Multiprogramming operating systems. Such operating
systems allow more than one process to be loaded into the executable memory at a time and the loaded
process shares the CPU using time multiplexing.
Time-division multiplexing (TDM) is a method of putting multiple data streams in a single signal by
separating the signal into many segments, each having a very short duration.
Transmitting multiple data stream in a single communication path.the data from different input channels
is divided into fixed length segments and combined in round robin fashion ito a single output data.over a
single channel transmission system and demultiplexed.
Sophisticated/statistical multiplexing(to avoid blank input stream).
The OS can use different policies to manage each queue (FIFO, Round Robin, Priority, etc.)
1 Running
When a new process is created, it enters into the system as in the running state.
2 Not Running
Processes that are not running are kept in queue, waiting for their turn to execute. Each
entry in the queue is a pointer to a particular process. Queue is implemented by using
linked list. Use of dispatcher is as follows. When a process is interrupted, that process is
transferred in the waiting queue. If the process has completed or aborted, the process is
discarded. In either case, the dispatcher then selects a process from the queue to execute.
Schedulers
Schedulers are special system software.Their main task is to select the jobs to be submitted
into the system and to decide which process to run.
Long-Term Scheduler
Short-Term Scheduler
Medium-Term Scheduler
2 Speed is lesser than short Speed is fastest among Speed is in between both short
term scheduler other two and long term scheduler.
5 It selects processes from It selects those processes It can re-introduce the process
pool and loads them into which are ready to into memory and execution
memory for execution execute can be continued.
Multithreading, A thread is also called a lightweight process. Threads provide a way to improve
application performance through parallelism. Threads represent a software approach to improving
performance of operating system by reducing the overhead thread is equivalent to a classical process.
Each thread belongs to exactly one process and no thread can exist outside a process. Each thread
represents a separate flow of control. Threads have been successfully used in implementing network
servers and web server. They also provide a suitable foundation for parallel execution of applications on
shared memory multiprocessors.
3 In multiple processing environments, each process executes the same code but has its own memory and
file resources.
All threads can share same set of open files, child processes.
4 If one process is blocked, then no other process can execute until the first process is unblocked.
While one thread is blocked and waiting, a second thread in the same task can run.
Advantages of Thread
Threads minimize the context switching time.
Use of threads provides concurrency within a process.
Efficient communication.
It is more economical to create and context switch threads.
Threads allow utilization of multiprocessor architectures to a greater scale and efficiency.
In this case, the thread management kernel is not aware of the existence of threads. The thread library contains
code for creating and destroying threads, for passing message and data between threads, for scheduling thread
execution and for saving and restoring thread contexts. The application starts with a single thread.
The Kernel maintains context information for the process as a whole and for individuals
threads within the process. Scheduling by the Kernel is done on a thread basis. The Kernel
performs thread creation, scheduling and management in Kernel space. Kernel threads are
generally slower to create and manage than the user threads.
Advantages
Kernel can simultaneously schedule multiple threads from the same process on multiple
processes.
If one thread in a process is blocked, the Kernel can schedule another thread of the same
process.
Kernel routines themselves can be multithreaded.
Disadvantages
Kernel threads are generally slower to create and manage than the user threads.
Transfer of control from one thread to another within the same process requires a mode switch to
the Kernel.
Multithreading Models
Many to many relationship.
Many to one relationship.
One to one relationship.
It is considered independent when any other processes operating on the system may not impact
a process. Process-independent processes don't share any data with other processes. On the
other way, a collaborating process may be affected by any other process executing on the
system. A cooperating process shares data with another.
Modularity refers to the division of complex tasks into smaller subtasks. Different cooperating
processes can complete these smaller subtasks. As a result, the required tasks are completed
more quickly and efficiently.
. Computation Speedup
4. Convenience
There are multiple tasks that a user requires to perform, such as printing, compiling, editing, etc.
It is more convenient if these activities may be managed through cooperating
processes.Concurrent execution of cooperating processes needs systems that enable processes
to communicate and synchronize their actions.
2. Cooperation by Communication
The cooperating processes may cooperate by using messages. If every process waits for a message from
another process to execute a task, it may cause a deadlock. If a process does not receive any messages, it
may cause starvation.
Producer-Consumer Problem
Producer Process
Both processes run simultaneously. The customer waits if there is nothing to consume.
There is a producer and a consumer; the producer creates the item and stores it in a buffer
while the consumer consumes it. For example, print software generates characters that the
printer driver consumes. A compiler can generate assembly code, which an assembler can use.
In addition, the assembler may produce object modules that are used by the loader.
What is Concurrency?
It refers to the execution of multiple instruction sequences at the same time. It occurs in an
operating system when multiple process threads are executing concurrently. These threads can
interact with one another via shared memory or message passing. Concurrency results in
resource sharing, which causes issues like deadlocks and resource scarcity. It aids with
techniques such as process coordination, memory allocation, and execution schedule to
maximize throughput.
A disk (e.g., Hard disk drive) has a file system, despite type and usage. Also, it
contains information about file size, file name, file location fragment information, and where disk data is
stored and also describes how a user or application may access the data. The operations like metadata,
file naming, storage management, and directories/folders are all managed by the file system.
On a storage device, files are stored in sectors in which data is stored in groups of sectors called
blocks. The size and location of the files are identified by the file system, and it also helps to
recognize which sectors are ready to be used. Other than Windows, there are some other
operating systems that contain FAT and NTFS file system. But Apple product (like iOS and
macOS) uses HFS+ as operating system is horizon by many different kinds of file systems.
Sometimes the term "file system" is used in the reference of partitions. For instance, saying, "on
the hard drive, two files systems are available," that does not have to mean the drive is divided
between two file systems, NTFS and FAT. But it means two separate partitions are there that use
the same physical disk.
, Protection
Protection and security requires that computer resources such as CPU, softwares, memory etc.
are protected. This extends to the operating system as well as the data in the system. This can
be done by ensuring integrity, confidentiality and availability in the operating system. The
system must be protect against unauthorized access, viruses, worms etc.
Username/ Password
Each user has a distinct username and password combination and they need to enter it
correctly before they can access the system.
The users need to punch a card into the card slot or use they individual key on a keypad
to access the system.
Different user attribute identifications that can be used are fingerprint, eye retina etc.
These are unique for each user and are compared with the existing samples in the
database. The user can only access the system if there is a match.
One Time Password
These passwords provide a lot of security for authentication purposes. A one time password
can be generated exclusively for a login every time a user wants to enter the system. It cannot
be used more than once. The various ways a one time password can be implemented are −
Random Numbers
The system can ask for numbers that correspond to alphabets that are pre arranged.
This combination can be changed each time a login is required.
Secret Key
A hardware device can create a secret key related to the user id for login. This key can
change each time.
Race Condition
A Race Condition typically occurs when two or more threads try to read, write and possibly
make the decisions based on the memory that they are accessing concurrently.
Critical Section
The regions of a program that try to access shared resources and may cause race conditions are
called critical section. To avoid race condition among the processes, we need to assure that only
one process at a time can execute within the critical section.
The critical section refers to the segment of code where processes access shared
resources, such as common variables and files, and perform write operations on them.
Since processes execute concurrently, any process can be interrupted mid-execution.
AFTER ACADEMY
In the Operating System, there are a number of processes present in a particular
state. At the same time, we have a limited amount of resources present, so those
resources need to be shared among various processes. But you should make sure
that no two processes are using the same resource at the same time because this
may lead to data inconsistency. So, synchronization of process should be there in
the Operating System. These processes that are sharing resources between each
other are called Cooperative Processes and the processes whose execution does
not affect the execution of other processes are called Independent Processes.
Race Condition
In an Operating System, we have a number of processes and these processes
require a number of resources. Now, think of a situation where we have two
processes and these processes are using the same variable "a". They are reading the
variable and then updating the value of the variable and finally writing the data in
the memory.
SomeProcess(){
...
read(a) //instruction 1
a = a + 5 //instruction 2
write(a) //instruction 3
...
}
In the above, you can see that a process after doing some operations will have to
read the value of "a", then increment the value of "a" by 5 and at last write the
value of "a" in the memory. Now, we have two processes P1 and P2 that needs to
be executed. Let's take the following two cases and also assume that the value of
"a" is 10 initially.
1. In this case, process P1 will be executed fully (i.e. all the three instructions)
and after that, the process P2 will be executed. So, the process P1 will first
read the value of "a" to be 10 and then increment the value by 5 and make it
to 15. Lastly, this value will be updated in the memory. So, the current value
of "a" is 15. Now, the process P2 will read the value i.e. 15, increment with
5(15+5 = 20) and finally write it to the memory i.e. the new value of "a" is
20. Here, in this case, the final value of "a" is 20.
2. In this case, let's assume that the process P1 starts executing. So, it reads the
value of "a" from the memory and that value is 10(initial value of "a" is
taken to be 10). Now, at this time, context switching happens between
process P1 and P2(learn more about context switching from here). Now, P2
will be in the running state and P1 will be in the waiting state and the context
of the P1 process will be saved. As the process P1 didn't change the value of
"a", so, P2 will also read the value of "a" to be 10. It will then increment the
value of "a" by 5 and make it to 15 and then save it to the memory. After the
execution of the process P2, the process P1 will be resumed and the context
of the P1 will be read. So, the process P1 is having the value of "a" as
10(because P1 has already executed the instruction 1). It will then increment
the value of "a" by 5 and write the final value of "a" in the memory i.e. a =
15. Here, the final value of "a" is 15.
In the above two cases, after the execution of the two processes P1 and P2, the
final value of "a" is different i.e. in 1st case it is 20 and in 2nd case, it is 15. What's
the reason behind this?
The processes are using the same resource here i.e. the variable "a". In the first
approach, the process P1 executes first and then the process P2 starts executing.
But in the second case, the process P1 was stopped after executing one instruction
and after that the process P2 starts executing. And here both the processes are
dealing on the same resource i.e. variable "a" at the same time.
Here, the order of execution of processes changes the output. All these processes
are in a race to say that their output is correct. This is called a race condition.
Critical Section
The code in the above part is accessed by all the process and this can lead to data
inconsistency. So, this code should be placed in the critical section. The critical
section code can be accessed by only one process at a time and no other process
can access that critical section code. All the shared variables or resources are
placed in the critical section that can lead to data inconsistency.
A context is the contents of a CPU's registers and program counter at any point in
time. Context switching can happen due to the following reasons:
When a process of high priority comes in the ready state. In this case, the
execution of the running process should be stopped and the higher priority
process should be given the CPU for execution.
When an interruption occurs then the process in the running state should be
stopped and the CPU should handle the interrupt before doing something
else.
When a transition between the user mode and kernel mode is required then
you have to perform the context switching.
Firstly, the context of the process P1 i.e. the process present in the running
state will be saved in the Process Control Block of process P1 i.e. PCB1.
Now, you have to move the PCB1 to the relevant queue i.e. ready queue, I/O
queue, waiting queue, etc.
From the ready state, select the new process that is to be executed i.e. the
process P2.
Now, update the Process Control Block of process P2 i.e. PCB2 by setting
the process state to running. If the process P2 was earlier executed by the
CPU, then you can get the position of last executed instruction so that you
can resume the execution of P2.
Similarly, if you want to execute the process P1 again, then you have to
follow the same steps as mentioned above(from step 1 to 4).
For context switching to happen, two processes are at least required in general, and
in the case of the round-robin algorithm, you can perform context switching with
the help of one process only.
The time involved in the context switching of one process by other is called the
Context Switching Time.
What is Deadlock?
Deadlock is a situation where two or more processes are waiting for each other.
For example, let us assume, we have two processes P1 and P2. Now, process P1 is
holding the resource R1 and is waiting for the resource R2. At the same time, the
process P2 is having the resource R2 and is waiting for the resource R1. So, the
process P1 is waiting for process P2 to release its resource and at the same time,
the process P2 is waiting for process P1 to release its resource. And no one is
releasing any resource. So, both are waiting for each other to release the resource.
This leads to infinite waiting and no work is done here. This is called Deadlock.
Coffman conditions
Hold and Wait: A process can hold a number of resources at a time and at
the same time, it can request for other resources that are being held by some
other process. For example, a process P1 can hold two resources R1 and R2
and at the same time, it can request some resource R3 that is currently held
by process P2.
No preemption: A resource can't be preempted from the process by another
process, forcefully. For example, if a process P1 is using some resource R,
then some other process P2 can't forcefully take that resource. If it is so, then
what's the need for various scheduling algorithm. The process P2 can request
for the resource R and can wait for that resource to be freed by the process
P1.
Circular Wait: Circular wait is a condition when the first process is waiting
for the resource held by the second process, the second process is waiting for
the resource held by the third process, and so on. At last, the last process is
waiting for the resource held by the first process. So, every process is
waiting for each other to release the resource and no one is releasing their
own resource. Everyone is waiting here for getting the resource. This is
called a circular wait.
Deadlock will happen if all the above four conditions happen simultaneously.
Difference between
Deadlock and Starvation
There is a difference between a Deadlock and Starvation. You shouldn't get
confused between these. In the case of Deadlock, each and every process is waiting
for each other to release the resource. But in the case of starvation, the high
priority processes keep on executing and the lower priority processes keep on
waiting for its execution. So, every deadlock is always starvation, but every
starvation is not a deadlock. Deadlock is infinite waiting but starvation is not an
infinite waiting. Starvation is long waiting. If the higher priority processes don't
come, then the lower priority process will get a chance to be executed in case of
starvation. So, in the case of starvation, we have long waiting and not infinite
waiting.
1
Symbolic addresses
The addresses used in a source code. The variable names, constants,
and instruction labels are the basic elements of the symbolic address
space.
2
Relative addresses
At the time of compilation, a compiler converts symbolic addresses into
relative addresses.
3
Physical addresses
The loader generates these addresses at the time when a program is
loaded into main memory.
Virtual and physical addresses are the same in compile-time and load-time address-binding
schemes. Virtual and physical addresses differ in execution-time address-binding scheme.
The set of all logical addresses generated by a program is referred to as a logical address
space. The set of all physical addresses corresponding to these logical addresses is referred to
as a physical address space.
The runtime mapping from virtual to physical address is done by the memory management unit
(MMU) which is a hardware device.
Memory management :Allocation and deallocation of process between RAM and disk drive.