Introduction

The operating system belongs to the system software category. It basically manages all resources on your computer. An operating system serves as an interface between software and various parts of a computer or computer hardware. An operating system is designed to manage a computer’s shared resources and tasks. A fully integrated set of special programs that manage all computer tasks. It controls and monitors the running of all other programs on your computer, including applications and other system software on your computer.

OPERATING SYSTEM
OPERATING SYSTEM

Types of OS

The operating system does all the basic tasks like managing files, processes and memory. Thus, the operating system acts as the manager of all resources. resource manager. The operating system thus becomes the interface between the user and the machine.

Operating system type: Some commonly used operating systems are:

  1. Batch Operating System
  2. Time-Sharing Operating Systems
  3. Distributed Operating System
  4. Network Operating System
  5. Real-Time Operating System

Simple Batch Operating System

A simple batch operating system is a type of operating system in which the jobs are submitted to the computer driver in the form of batches, and the driver runs the jobs one after the other without any stoner intervention. In a simple batch operating system, there’s no conception of time- sharing or multi-programming, and only one program can be executed at a time.

Time Sharing Systems

A time-sharing system is a type of operating system that allows multiple users to simultaneously share a single computer system’s resources such as CPU time, memory, and peripherals. The idea behind a time-sharing system is to maximize the utilization of the computer system by allowing many users to use it at the same time.

Real-Time Systems

Real-time systems are computer systems that are designed to process and respond to events or data inputs within strict time constraints. These systems are used in a variety of applications where timing is critical, such as in aviation, automotive, and industrial control systems.

Multiprocessor Systems

A multiprocessor system is a computer system that uses two or more central processing units (CPUs) to perform tasks. Multiprocessor systems can be divided into two categories: symmetric multiprocessing (SMP) and asymmetric multiprocessing (AMP).

Distributed Systems

Distributed systems refer to a collection of independent computers that work together as a single system. These computers are connected through a network, and they communicate and coordinate with each other to achieve a common goal.

Distributed systems are used in various applications, such as cloud computing, social networks, peer-to-peer networks, and online gaming. One of the primary advantages of distributed systems is that they can provide high scalability, fault tolerance, and availability. Additionally, distributed systems can be designed to be highly resilient to failures and able to handle large amounts of data processing.

OS Services

An OS is a collection of software programs that manage computer hardware and help some common services. OS services can be astronomically distributed into three main types:

  1. System services.
  2. Application services.
  3. User services.

System Calls

System calls are the interface between user-level applications and the operating system. They provide a way for user-level applications to request services from the operating system, such as accessing hardware devices, managing memory, and interacting with the file system.

Process concepts

In operating systems, a process is an instance of a program that is being executed. It is the basic unit of execution in a computer system, and every running program is a process. The operating system manages and schedules processes to ensure that each process has a fair share of resources, such as CPU time and memory, and that they do not interfere with each other.

PCB(Process Control Block)

A data structure is maintained by the operating system for each process. It contains information about the process, such as its current state, program counter, CPU registers, memory allocation, and other relevant data.

Process Scheduling

Process scheduling is a process manager activity that removes a running process from the CPU and selects another process according to a specific strategy.

Process scheduling is an essential part of a multiprogramming operating system. These operating systems allow more than one process to be loaded into executable memory at the same time, and the loaded processes share the CPU using time multiplexing.

Categories of Scheduling

  1. Non-preemptive:
  2. Preemptive.

Operations on Processes

Operations on processes are a set of actions that can be performed on processes running on a computer system. These operations include.

  1. Creation.
  2. Suspension.
  3. Resumption.
  4. Termination.
  5. Blocking.

Co-Operating Process

A computer system has many processes that can be independent processes or cooperating processes running on the operating system. A process is said to be independent when it cannot or cannot affect other processes running on the system. It is understood that any process that does not share data (temporary or permanent) with other processes is process-independent. A cooperating process, on the other hand, is a process that affects or can be affected by other processes running on the computer. Collaborative processes are those that communicate with other processes.

IPC

IPC( Interprocess Communication) is a medium that allows different processes to communicate with each other in an operating system. There are several styles of IPC available in different operating systems, including.

  1. Pipes.
  2. Message Queues.
  3. Shared Memory.
  4. Sockets.
  5. Semaphores.

Threads

A thread is also called a thread of execution or a flow of control because it is a single sequential flow of execution of process tasks. All operating systems have a way to run a thread inside a process. Also, there can be more than one thread inside a process. Each thread in the same process uses a separate program counter-activation record and control block stack. Threads are often referred to as lightweight processes.

Benefits

  1. Increased system throughput: When a process is split into multiple threads and each thread is treated as a task, the number of tasks executed per unit of time increases. This is why the throughput of the system also increases.
  2. Efficient use of multiprocessor systems: You can schedule more than one thread on more than one processor if you have more than one thread in the same process.
  3. communication: Multi-threaded communication is easy because the threads share the same address space. On the other hand, processes use only a few exclusive communication strategies to communicate between two processes.
  4. Share your resources. Resources can be shared by all threads within a process, such as code, data, and files. memo. Stacks and registers cannot be shared between threads. Each thread has a stack and registers.

User & Kernel Threads

In operating systems, a thread is a basic unit of execution that is scheduled by the operating system’s scheduler. Threads can be classified into two main types: user-level threads and kernel-level threads.

User-level threads are managed by the user-level threads library or the application itself, without direct intervention from the operating system kernel. These threads are created, scheduled, and managed by the application, and are invisible to the kernel. User-level threads are usually more lightweight than kernel-level threads, and context switching between them is faster. However, they can be limited in terms of their ability to make system calls, as a system call will block the entire process, including all its threads.

CPU Scheduling

In a single program system like MS-DOS, when a process is waiting for some I/O operation, the CPU is left idle. This is overhead because it wastes time and causes starvation problems. However, in a multiprogramming system, the CPU is not idle while waiting for a process and starts executing other processes. The operating system has to decide which process to allocate the CPU to.

In a multiprogramming system, the operating system schedules processes on the CPU to make the most of them, and this process is called CPU scheduling. Operating systems schedule processes using a variety of scheduling algorithms.

Scheduling Criteria

Different CPU scheduling algorithms have different properties, and the choice of a particular algorithm depends on a number of factors. A number of criteria have been proposed to compare CPU scheduling algorithms.

Criteria include:

  1. CPU Utilization.
  2. Throughput.
  3. Execution time.
  4. waiting time.
  5. Response time

Preemptive & Non-preemptive scheduling

  1. Plan ahead

Preemptive scheduling is used when a process transitions from a running state to a ready state or from a waiting state to a ready state. Resources (mostly CPU cycles) are allocated to a process for a limited amount of time and then removed, and if that process still has maximum CPU time remaining, the process is put back into the ready queue. This process remains in the ready queue until it gets the next chance to run.

  1. Plan without preemption:

Non-preemptive scheduling is used when a process terminates or when a process transitions from a running state to a waiting state. In this scheduling, once resources (CPU cycles) are allocated to a process, the process retains the CPU until it terminates or reaches a waiting state. In non-preemptive scheduling, processes running on the CPU are not interrupted while running. Instead, you can wait for the process to complete its maximum CPU time and then allocate the CPU to another process.

Scheduling Algorithms

A process scheduler schedules various processes to be assigned to CPUs based on specific scheduling algorithms. There are six popular process scheduling algorithms that will be discussed in this chapter.

First-Come, First-Served (FCFS) Scheduling
Shortest-Job-Next (SJN) Scheduling
Priority Scheduling
Shortest Remaining Time
Round Robin(RR) Scheduling
Multiple-Level Queues Scheduling

These algorithms are either non-preemptive or preemptive. Non-preemptive algorithms are designed so that once a process enters the running state, it cannot be preempted until the allotted time has expired, while preemptive scheduling is priority-based, allowing the scheduler to preempt a running process with a lower priority at any time. -Priority process enters the ready state.

Process Synchronization

An operating system is the software that manages all the applications on your device and basically helps your computer run smoothly. For this reason, the operating system must perform many tasks, sometimes simultaneously. This is usually not a problem as long as these concurrent processes do not use shared resources.

Critical Section Problem

A critical section is a segment of code that has access to shared variables. Atomic operations are required in the critical section. That is, only one process can run in a critical section at a time. All other processes must wait to run in the critical section.

In the diagram above, the input section handles input to the critical section. Receives the resources needed to run the process. The end section handles the end of critical sections. Frees resources and notifies other processes that critical sections are empty.

Critical Regions

Sometimes a process needs to access shared memory or files or perform other important tasks that can lead to race conditions. The part of a program where shared memory is accessed is called a critical section or critical section.

Race conditions can be avoided if two processes can be coordinated so that they are not in the critical region at the same time. This requirement prevents race conditions but is not sufficient for accurate and efficient communication of parallel processes using shared data.

Synchronization Hardware

We explore some additional solutions to the critical section problem using a variety of methods ranging from timing hardware to hardware to software APIs available to application developers. These solutions are based on the blocking principle. However, the design of these locks can be quite complex.

These hardware features can simplify all programming tasks and improve system efficiency. Here we present some simple hardware instructions that can be used on many systems and show you how to use them effectively to troubleshoot critical section issues. If only I could prevent an interrupt from firing while a shared variable is being changed. Critical section problems are straightforward to solve in a single processor environment. This allows the current command sequence to be executed in order without being preempted. No other commands are executed, so there are no unexpected changes to shared variables. This is the approach used by non-preemptive kernels. Unfortunately, however, this solution is not very feasible in a multiprocessor environment. Disabling interrupts on multiple processors can take a long time because messages are broadcast to all processors.

Semaphores

A semaphore is an integer variable used to solve critical section problems with two atomic operations, wait and signal, used to synchronize processes.

The wait and signal definitions are:

  1. wait

The wait operation decrements the argument S if it is positive. If S is negative or zero, no operation is performed.

wait(S)
{
while (S<=0);

S--;
}
  1. signal A signal operation increments the value of its argument S.
signal(S)
{
S++;
}

Classic Problems of Synchronization

This tutorial covers a number of classic timing problems.

Semaphores can be used for other synchronization operations besides mutual exclusion.

Here are some classic problems that describe the deficiencies of process synchronization in systems with cooperating processes.

We will discuss three issues:

  1. Bounded Buffer (Producer-Consumer) Problem
  2. Dining Philosophers Problem
  3. The Readers Writer’s Problem

Deadlocks

A deadlock is a situation in which a series of processes are blocked because each process holds a resource and another process is waiting to acquire another resource.

Consider the case where two trains are moving towards each other on the same track, and there is only one track, and neither can move when both trains are in front of each other. A similar situation occurs in operating systems when there is more than one process holding one resource and waiting for another.

System Model

In a system model, resources are represented by nodes and processes by edges in a graph. Each resource has a maximum capacity, and each process requires a certain amount of the resource to complete its task. A deadlock can occur if the resources are allocated in such a way that the processes cannot proceed.

There are several algorithms that can be used to detect and prevent deadlocks in a system. One such algorithm is the Banker’s algorithm, which uses a resource allocation graph to determine whether a system is in a safe state (i.e., there is no deadlock). Another algorithm is the deadlock avoidance algorithm, which prevents deadlocks by dynamically allocating resources to processes.

Deadlock Characterization

A deadlock in an operating system occurs when two or more processes require a resource held by another process to complete execution.

Deadlock occurs when the four Coffman conditions are met. However, these conditions are not mutually exclusive. They are given as –

  1. Mutual Exclusion
  2. Hold and Wait
  3. No Preemption
  4. Circular Wait

Methods for Handling Deadlock

A deadlock occurs when a process or set of processes hangs while waiting for a resource held by another waiting process. This is an unfavourable condition. If your system encounters a deadlock, there are several methods you can use to resolve it.

Deadlock Prevention

  1. Wait-Die Scheme
  2. Wound-Wait Scheme

Deadlock Prevention

If you are simulating a deadlock where a table is standing on four legs, you can also simulate a deadlock on four legs with four conditions that cause deadlock when they occur simultaneously.

However, if one of the table’s legs breaks, the table will definitely fall. The same goes for deadlocks. Deadlock can be prevented by violating any of the four necessary conditions and preventing them from occurring together.

Deadlock avoidance

In deadlock avoidance, requests for any resource are granted if the resulting system state does not cause a deadlock in the system. System health is continuously checked for secure and non-secure status.

To avoid deadlocks, the process must tell the OS the maximum amount of resources it can request to complete execution.

The simplest and most useful approach is to declare the maximum amount of each resource type a process needs. Deadlock avoidance algorithms check resource allocation to avoid circular wait conditions. safe and unsafe conditions

Deadlock Detection and Recovery

Deadlock Detection

  1. If the resource has one instance:

In this case, you can run an algorithm that checks cycles in the resource allocation graph to detect deadlocks.

2. For multiple resource instances:

Loop detection is a necessary but not sufficient condition for deadlock detection, in which case the system may or may not deadlock depending on the circumstances.

Deadlock Recovery

Traditional operating systems like Windows do not handle deadlock recovery because it is a time- and space-consuming process. Real-time operating systems use deadlock recovery.

recovery method

  1. Terminate Process: Kills all processes involved in the deadlock. The process of killing one by one. After killing each process, it checks for deadlocks again and continues repeating the process until the system breaks the deadlock.
  2. Resource Preemption: Allows the system to recover from a deadlock by removing resources from the process involved in the deadlock and assigning the preempted resource to another process. In this case, the system starves.

Memory Management

Memory is an important part of a computer used to store data. Taking care of your computer system is very important because the amount of RAM available to your computer system is very limited. At any given moment, many processes are competing for this. Also, multiple processes run concurrently to improve performance. This requires maintaining multiple processes in main memory, so managing them efficiently is even more important.

Logical Addresses

Logical addresses are generated by the processor while a program is running. Logical addresses are virtual addresses because they do not physically exist, which is why they are also called virtual addresses. This address is used by the CPU as a reference to access the physical memory location. The term “logical address space” is used to refer to the set of all logical addresses generated by a program.
A hardware device called the memory management unit is used to map logical addresses to their corresponding physical addresses.

Physical Address

A physical address specifies the physical location of required data in memory. Users do not directly work with physical addresses, but have access to their logical addresses. The user program creates a logical address and thinks the program is running at that logical address, but since the program needs physical memory to run, the MMU must map the logical address to a physical address before it can be used. The term “physical address space” is used for any physical address that corresponds to a logical address in a logical address space.

Swapping

Swap is a memory management scheme that temporarily moves all processes from main memory to secondary, making main memory available to other processes. Used to improve the use of main memory. The place in secondary memory where paged processes are stored is called swap space.

The purpose of paging in an operating system is to access data on the hard drive and move it to RAM so that it can be used by applications. It is important to remember that paging is only used when there is no data in RAM. The swap process affects system performance, but it helps to have more than one process running. For this reason, paging is also referred to as memory compression.

Contiguous Memory Allocation

It is a kind of memory allocation method. When a process requests memory, one contiguous chunk of memory block is allocated according to the requirement.

This will eventually divide the memory into fixed-size partitions and assign each partition to a single process. However, this limits the degree of multiprogramming to the number of fixed partitions created in memory. This allocation also leads to internal fragmentation. For example, assume that the fixed-size block of memory allocated to the process is slightly larger than needed. In this case, the memory space left in the block is called internal fragmentation. When a process on a partition is terminated, the partition becomes free to run other processes.

Non-Contiguous Memory Allocation

This allows a process to acquire multiple blocks of memory from different memory locations depending on its requirements. Persistent memory allocation also reduces memory wastage due to internal and external fragmentation because it uses memory holes created by internal and external fragmentation.

Two methods of making a process’ physical address space non-contiguous are paging and partitioning. Persistent memory allocation divides a process into blocks (pages or segments) that are allocated to different regions of memory based on memory availability.

Segmentation

In operating systems, segmentation is a memory management technique that divides memory into variable-sized chunks. Each part is known as a segment that can be assigned to a process.

Detailed information about each segment is stored in a table called the segment table. A segment table is stored in one (or several) segments.

A segment table basically contains two pieces of segment information.

  • Base: The base address of the segment.
  • Constraint: The length of the segment.

Segmentation With Paging

Segmentation with paging is a memory management scheme that combines two techniques, segmentation and paging. In segmentation, memory is divided into segments, where each segment represents a logical unit of a program such as a code segment or a data segment. Each segment can be of different sizes and can be allocated to different parts of a program. Paging, on the other hand, divides the physical memory into fixed-sized pages and maps them to logical memory.

Virtual Memory

computer can handle more memory than is physically installed in your system. This extra memory is actually called virtual memory and is a hard disk partition configured to emulate your computer’s RAM.

The main noticeable benefit of this approach is that programs can occupy more space than physical memory. Virtual memory serves two purposes. First, physical memory usage can be scaled at the expense of disk usage. Second, memory can be protected because each virtual address is translated into a physical address.

Demand Paging

According to the concept of Virtual Memory, in order to execute some process, only a part of the process needs to be present in the main memory which means that only a few pages will only be present in the main memory at any time.

However, deciding, which pages need to be kept in the main memory and which need to be kept in the secondary memory, is going to be difficult because we cannot say in advance that a process will require a particular page at particular time.

Therefore, to overcome this problem, there is a concept called Demand Paging is introduced. It suggests keeping all pages of the frames in the secondary memory until they are required. In other words, it says that do not load any page in the main memory until it is required.

Page Replacement

Page replacement is required in operating systems that use demand-paged virtual memory. As you know, in on-demand paging, only a set of process pages are loaded into memory. This is done so you can have more processes in memory at the same time.

When a page residing in virtual memory is requested to be executed by a process, the operating system must determine which page is to be replaced with the requested page. This process is called page replacement and is an important component of virtual memory management.

Page Replacement Algorithms

Page replacement algorithms are used in operating systems to manage the memory of a computer system. These algorithms are responsible for selecting which page from memory should be evicted or replaced with a new page that is needed. There are several page replacement algorithms, including First-Come-First-Serve (FCFS) and Least Recently Used (LRU).

First-Come-First-Serve (FCFS)

First- Come- First- Serve( FCFS) This is a simple runner relief algorithm where the runner that has been in memory the longest is replaced first. This algorithm works on the principle of” first in, first out”( FIFO). When a runner needs to be replaced, the operating system looks for the runner that has been in memory the longest and evicts it. This algorithm is easy to apply but doesn’t take into account how frequently a runner is penetrated or how important it’s to the system.

Least Recently Used (LRU)

Least lately habituated( LRU) This algorithm replaces the runner that has not been used for the longest period of time. The idea behind this algorithm is that runners that haven’t been penetrated for a long time are less likely to be demanded in the future. When a runner needs to be replaced, the operating system looks for the runner that has not been penetrated for the longest time and evicts it. This algorithm is more effective than FCFS as it takes into account the operation of runners and tries to keep the most constantly used runners in memory.

Allocation of Frames

The operating system’s main memory is divided into frames. Processes are stored in these frames, and when a process is stored as a frame, the CPU can start the process. As a result, the operating system must allocate enough frames for each process. As a result, the operating system allocates frames using a different algorithm.

Demand paging is used to implement virtual memory, an important feature of the operating system. This requires the development of page replacement mechanisms and frame allocation systems. When there are multiple processes, the frame allocation method is used to determine the number of frames allocated to each process. Factors limiting staffing strategies include.

Thrashing

Thrashing occurs when a computer’s virtual memory resources are overloaded, resulting in persistent paging states and page faults that prevent most applications from processing at the application layer. This will lead to poor performance or breakdown of your computer. This situation may continue indefinitely until the user closes some running applications or until active processes release additional virtual memory resources.

File Systems

The file system is the part of the operating system responsible for managing files. Provides mechanisms for storing data and accessing file contents, including data and programs. Some operating systems treat everything as a file, like Ubuntu. The file system is the part of the operating system responsible for managing files. Provides mechanisms for storing data and accessing file contents, including data and programs. Some operating systems treat everything as a file, like Ubuntu.

File concept

An operating system can provide a logical representation of information stored on disk, and this logical unit is called a file. Information stored in files is not lost in case of power failure.

This file helps you write data to your computer. A sequence of bits, bytes, or records whose structure is determined by the owner and which depends on the type of file.

Different types of files are:

  • Executable file
  • Source file
  • Object file
  • Text file
  • Image file

Access Methods

When a file is used, information is read and accessed from the computer’s memory, and there are many ways to access this information about a file. Some systems provide only one method of file access. Other systems, such as IBM’s, support a variety of access methods, and choosing the right one for a particular application is a major design challenge.

Allocation methods-contiguous

In operating systems, conterminous allocation is a system of allocating fragment space for lines. Under this system, lines are stored in successive blocks on the fragment. There are two main types of conterminous allocation styles

  1. Single conterminous allocation: In this system, a train is allocated a single conterminous block of fragment space, which means that all of the blocks allocated to the train are conterminous to each other on the fragment.
  2. Multiple conterminous allocation: In this system, a train is allocated multiple conterminous blocks of fragment space, which means that the blocks allocated to the train aren’t inescapably conterminous to each other, but are still conterminous within the train.

Linked Index Allocation

Single-level linked Index Allocation

When placing an index, the size of the file depends on the size of the disk blocks. Multiple index blocks must be chained together to allow for large files. When placing a linked index

  1. small header with file name
  2. Set of first 100 block addresses
  3. Pointer to another index block

Multilevel Index Allocation

Index tiering has different levels of indexes. There is an outer level index block that contains a pointer to an inner level index block and the inner level index block contains a pointer to the file data.

  1. The outer level index is used to find the inner level index.
  2. An inner-level index is used to find the desired block of data.

Single Level

The easiest way is to create one big list of all files on disk. The entire system contains only one directory to which all files in the file system must be addressed. The directory contains one entry for each file in the file system.

Tree-Structured

In a tree-structured directory system, every directory entry can be either a file or a subdirectory. A tree-structured directory system overcomes the disadvantages of a two-level directory system. You can now group similar files into one directory.

Each user has their own directory and cannot enter another user’s directory. However, the user has permission to read the root data, but cannot write or modify it. Only system administrators have full access to the root directory.

Acyclic Graph and General Graph Directory

An acyclic graph, also known as a directed acyclic graph (DAG), is a type of directed graph that has no cycles, i.e., there is no path that starts and ends at the same node. In other words, if you follow the arrows of an acyclic graph, you will never come back to a node you have visited before.

A general graph, also known as an undirected graph, is a type of graph where edges have no direction. In other words, the relationship between the nodes is symmetric, and you can travel from one node to another in both directions.

File protection

File protection refers to the measures taken to secure files and prevent unauthorized access, modification, or destruction of data. There are several methods for file protection, including encryption, access controls, and backups.

Encryption involves encoding data in a way that can only be read by authorized individuals or devices. This can be accomplished using software or hardware-based encryption tools. Access controls, on the other hand, restrict who can access a file, and what actions they can perform on it. This can include permissions, passwords, or biometric authentication methods.

Disk Management

The operating system is responsible for various disk management tasks. Modern operating systems are constantly expanding their range of services and add-ons, and all operating systems implement four basic operating system management functions. These features include:

  1. Process Management
  2. Memory Management
  3. File and Disk Management
  4. I/O System Managemen

Secondary Storage Structure

Secondary storage devices are devices whose memory is non-volatile. That is, stored data will not be corrupted when the system is turned off. Here are a few things to keep in mind about secondary storage:

  • Secondary storage is also known as secondary storage.
  • Secondary memory is less expensive compared to primary memory such as RAM.
  • Secondary storage is slower than primary storage.
  • As a result, infrequently accessed data is stored on secondary storage.
  • Some examples: magnetic disks, magnetic tapes, removable flash drives, etc.

Disk Structure

As we know that one computer can do many things at the same time, we also need to manage all the running processes running on the system at the same time. With the help or advent of multiprogramming, we can run many programs at the same time. Therefore, in order to manage memory and allocate it to all processes, the operating system uses the concept of disk scheduling.

This divides the CPU time between different processes and makes sure all processes are running correctly. So Disk Scheduling Will specifies which process the CPU will run. So scheduling means running all the processes given to the CPU at the same time.

Disk Reliability

Disk reliability refers to the probability that a disk or storage device will function without failure over a given period of time. Reliability is a critical factor in data storage, as any failure or corruption of data can result in data loss or system downtime.

There are several factors that can impact disk reliability, including the quality of the hardware components used in the disk, the operating conditions in which the disk is used (such as temperature and humidity), the workload and usage patterns of the disk, and the effectiveness of the disk’s error correction and fault tolerance mechanisms.