Overview of Operating Systems Explained
Overview of Operating Systems Explained
⚡
primarily designed for mobile devices such as smartphones and tablets. It
offers a rich ecosystem of applications and customization options.
Operating System in One Video 7. Real-Time Operating Systems (RTOS): RTOS is designed for systems that
require deterministic and real-time response. It is commonly used in
embedded systems, control systems, and IoT devices.
memory simultaneously, and the CPU switches between them to execute In summary, a program is a set of instructions, a process is an instance of a
instructions. The purpose of multiprogramming is to maximize CPU utilization program in execution with its own resources and memory space, and a thread is
and keep the CPU busy by quickly switching between different programs a unit of execution within a process that allows for the concurrent execution of
when one is waiting for I/O or other operations. Each program has its own tasks. Processes provide isolation and protection between different instances of a
separate memory space. program, while threads within a process share resource and enable parallel
execution of tasks.
4. Multitasking:
Multitasking is a technique that allows multiple tasks or processes to run
concurrently on a single CPU. The CPU time is divided among the tasks,
4. Various Process States
giving the illusion of parallel execution. The operating system switches
between tasks rapidly, giving each task a time slice or quantum to execute.
Multitasking is commonly used in modern operating systems to provide
responsiveness and the ability to run multiple applications simultaneously.
Process:
A process is an instance of a program in execution. When a program is
loaded into memory and executed, it becomes a process. A process is an
independent entity with its own memory space, resources, and execution
context. It has its own program counter, stack, and variables. Processes are
managed by the operating system, and each process runs in its own
protected memory space. Processes can be concurrent and communicate
with each other through inter-process communication mechanisms.
Thread:
A thread is a unit of execution within a process. It represents a sequence of
5. CPU scheduling Algorithms
instructions that can be scheduled and executed independently. Threads
share the same memory space and resources within a process. Multiple CPU scheduling algorithms are used by the operating system to determine the
threads within a process can run concurrently, allowing for parallel execution order in which processes are executed on the CPU.
of tasks. Threads within the same process can communicate and share data 1. First-Come, First-Served (FCFS):
more easily compared to inter-process communication. However, each In the FCFS scheduling algorithm, the process that arrives first is executed
thread has its own program counter and stack. first. It follows a non-preemptive approach, meaning that once a process
2. Shortest Job Next (SJN) or Shortest Job First (SJF): To maintain data integrity and avoid conflicts, only one process or thread should
SJN or SJF scheduling selects the process with the shortest total execution be allowed to enter the critical section at a time. This ensures that no two
time next. It can be either non-preemptive or preemptive. In the non- processes interfere with each other and modify shared resources simultaneously,
preemptive variant, the process continues executing until it completes, preventing inconsistencies or incorrect results.
whereas in the preemptive variant, if a new process with a shorter burst time
arrives, the currently running process may be preempted. SJN/SJF aims to
minimize the average waiting time and is suitable when burst times are 7. Process synchronisation
known in advance. Process synchronization is like a traffic signal that helps regulate the flow of
vehicles at an intersection. In the context of computing, it refers to techniques
3. Round Robin (RR):
and mechanisms used to coordinate the execution of processes or threads so
Round Robin is a preemptive scheduling algorithm that assigns a fixed time
that they can work together harmoniously.
quantum (e.g., 10 milliseconds) to each process in a circular manner. Once a
process exhausts its time quantum, it is moved to the back of the ready Imagine multiple processes or threads working on different tasks simultaneously.
queue, allowing the next process in line to execute. RR provides fair Process synchronization ensures that they cooperate and communicate
execution to all processes but may suffer from high context-switching effectively to avoid conflicts and ensure proper order of execution. It helps
overhead and may not be efficient for long-running processes. prevent issues like race conditions, data inconsistencies, or deadlocks that can
arise when multiple processes or threads access shared resources
4. Priority Scheduling:
simultaneously.
Priority scheduling assigns a priority value to each process, and the CPU is
allocated to the process with the highest priority. It can be either preemptive Here are the key requirements of synchronization mechanisms:
or non-preemptive. In preemptive priority scheduling, if a higher-priority 1. Mutual Exclusion: The synchronization mechanism should enforce mutual
process arrives, the currently running process may be preempted. In non- exclusion, which means that only one process or thread can access a shared
preemptive priority scheduling, the process continues executing until it resource or enter a critical section at a time. It ensures that concurrent
completes or voluntarily gives up the CPU. Priority scheduling can suffer from access to shared resources does not result in conflicts or inconsistencies.
starvation if a lower-priority process never gets a chance to execute.
2. Progress: The synchronization mechanism should allow processes or
5. Multilevel Queue Scheduling: threads to make progress by ensuring that at least one process/thread can
Multilevel queue scheduling divides the ready queue into multiple priority enter the critical section when it desires to do so. It avoids situations where
queues, each with its own scheduling algorithm. Processes are initially all processes/threads are blocked indefinitely, leading to a deadlock.
placed in the highest-priority queue and can move between queues based on
predefined criteria. This approach allows for the differentiation of processes 3. Bounded Waiting: The synchronization mechanism should provide a
based on their priority or characteristics, such as foreground or background guarantee that a process/thread waiting to enter a critical section will
tasks. Each queue can use a different scheduling algorithm, such as FCFS, eventually be allowed to do so. It prevents a process/thread from being
SJF, or RR, suitable for the processes within that queue. starved or waiting indefinitely to access a shared resource
Here are some of the mechanisms that fulfill the above process synchronization two processes cannot use the same resource at the same time.
requirements:
Hold and Wait
1. Locks/Mutexes: Locks or mutexes (mutual exclusions) provide a simple and A process waits for some resources while holding another resource at the
effective way to achieve mutual exclusion. They allow only one process or same time.
thread to acquire the lock at a time, ensuring exclusive access to a shared
No preemption
resource or critical section. Locks can be implemented using hardware
The process once scheduled will be executed till the completion. No other
instructions or software constructs.
process can be scheduled by the scheduler meanwhile.
2. Semaphores: Semaphores are synchronization objects that can be used to
Circular Wait
control access to shared resources. They can be implemented as binary
All the processes must be waiting for the resources in a cyclic manner so that
semaphores (mutexes) or counting semaphores. Counting semaphores allow
the last process is waiting for the resource which is being held by the first
a specified number of processes or threads to access a shared resource
process.
simultaneously. Semaphores provide mechanisms for mutual exclusion,
signaling, and coordination.
3. Read-Write Locks: Read-write locks provide synchronization mechanisms 10. Deadlock Handling Techniques
for scenarios where multiple readers can simultaneously access a shared 1. Deadlock Prevention: Deadlock prevention techniques aim to eliminate one
resource without conflicts, but exclusive access is required for writers. Read or more of the necessary conditions for deadlock to occur. These conditions
locks can be acquired simultaneously by multiple readers, while write locks include mutual exclusion, hold and wait, no preemption, and circular wait. By
are exclusive. Read-write locks allow for better concurrency when reading is ensuring that one or more of these conditions are not satisfied, deadlocks
more frequent than writing. can be prevented from happening in the first place. However, prevention
techniques may impose restrictions on resource allocation and may not be
always feasible or efficient.
9. Deadlock
2. Deadlock Avoidance: Deadlock avoidance techniques use resource
A Deadlock is a situation where
allocation algorithms and resource request protocols to avoid situations that
each of the computer processes
may lead to deadlocks. These techniques involve the use of resource
waits for a resource that is being
allocation graphs, bankers' algorithm, or other dynamic allocation strategies.
assigned to another process. In
The idea is to have a system that can predict whether granting a resource
this situation, none of the
request will lead to a potential deadlock. If a request might cause a deadlock,
process gets executed since the
it is delayed until granting it will not cause any issues.
resource it needs, is held by
some other process that is also 3. Deadlock Detection: Deadlock detection techniques involve periodically
waiting for some other resource examining the resource allocation state to determine if a deadlock has
to be released. occurred. This can be achieved through algorithms such as the resource-
allocation graph or the Banker's algorithm. When a deadlock is detected, the
Necessary Conditions for
system can take appropriate actions to resolve it, such as terminating
Deadlocks:
processes, resource preemption, or rolling back the system to a safe state.
Mutual Exclusion 4. Deadlock Recovery: Deadlock recovery techniques are used to recover
A resource can only be shared in a mutually exclusive manner. It implies that from a deadlock once it has been detected. This involves terminating one or
2. Best Fit: The best-fit algorithm searches for the smallest available memory
block that is large enough to accommodate the process. It aims to minimize
11. Memory Management leftover fragments by choosing the most optimal block. This algorithm can
Fixed partitioning and dynamic partitioning are two approaches used in memory lead to better overall memory utilization, but it may involve more time-
management systems to allocate and manage memory resources. Let's discuss consuming searches.
each approach:
3. Worst Fit: The worst-fit algorithm allocates the largest available memory
1. Fixed Partitioning: block to the process. This approach intentionally keeps larger fragments to
In fixed partitioning, memory is divided into fixed-sized partitions or blocks, accommodate potential future larger processes. While it may seem
and each partition is assigned to a specific process or task. The system counterintuitive, it can help reduce fragmentation caused by small processes
allocates a predetermined amount of memory to each partition, which and improve overall memory utilization.
remains fixed throughout the execution.
Fixed partitioning is relatively simple to implement and provides fast memory
13. Paging
allocation. However, it can lead to inefficient memory utilization due to
internal fragmentation, especially when processes have varying memory In Operating Systems, Paging is a storage mechanism used to retrieve
requirements. processes from the secondary storage into the main memory in the form of
pages.
2. Dynamic Partitioning:
Dynamic partitioning, also known as variable partitioning, addresses the The main idea behind the paging is to divide each process in the form of pages.
limitation of fixed partitioning by allowing memory to be allocated and The main memory will also be divided in the form of frames.
deallocated dynamically based on the size requirements of processes. One page of the process is to be stored in one of the frames of the memory. The
Dynamic partitioning provides better memory utilization compared to fixed pages can be stored at the different locations of the memory but the priority is
partitioning, as memory can be allocated based on actual requirements. always to find the contiguous frames or holes.
However, managing fragmentation and efficiently allocating and deallocating Pages of the process are brought into the main memory only when they are
memory can be more complex. required otherwise they reside in the secondary storage.
LRU works on the principle that pages that have been recently accessed are
more likely to be accessed again in the near future. By replacing the least
recently used pages, it aims to retain the frequently accessed pages in
memory, reducing the number of page faults and improving overall system
performance.
17. Segmentation
Segmentation divides processes into smaller subparts known as modules. The
divided segments need not be placed in contiguous memory. Since there is no
contiguous memory allocation, internal fragmentation does not take place. The
length of the segments of the program and memory is decided by the purpose of
the segment in the user program.
Hence, segmentation was introduced in which the code is divided into modules consider the position of the disk head or the proximity of the requests,
so that related code can be combined in one single block. resulting in potential delays if there are long seek times between requests.
2. SSTF (Shortest Seek Time First): This algorithm selects the request with
the shortest seek time from the current position of the disk head. It minimizes
18. Disk Management
the average seek time and reduces the overall disk access time. However, it
may lead to starvation of requests located farther away from the current
position.
3. SCAN: Also known as the elevator algorithm, SCAN moves the disk head in
one direction (e.g., from the outermost track to the innermost or vice versa)
and services requests along the way. Once it reaches the end, it changes
direction and continues the same process. This algorithm provides a fair
distribution of service and prevents starvation, but it may result in longer
response times for requests at the far ends of the disk.
4. C-SCAN (Circular SCAN): Similar to SCAN, C-SCAN moves the disk head
in one direction, but instead of reversing direction, it jumps to the other end of
the disk and starts again. This ensures a more consistent response time for
all requests, but it may cause delays for requests that arrive after the head
has passed their location.
5. LOOK: LOOK is a variant of SCAN that only goes as far as the last request
Seek Time in its current direction. Once there are no more requests in that direction, it
reverses direction. This reduces unnecessary traversal of the entire disk and
Seek time is the time taken in locating the disk arm to a specified track where the
improves response times for requests.
read/write request will be satisfied.
6. C-LOOK (Circular LOOK): Similar to C-SCAN, C-LOOK jumps to the other
Rotational Latency
end of the disk without servicing requests along the way. This reduces seek
It is the time taken by the desired sector to rotate itself to the position from where time and improves disk throughput.
it can access the R/W heads.
For images: [Link]