What is an OS?
Before diving into what an OS is, Why an OS?
Let’s say you have your device and you decide to run Instagram on it. Let’s just say we have this minimalistic device that has a CPU, GPU, memory, and a disk, but no OS. If we were to run Instagram on this system, Instagram would have all these resources allocated to it. And, if we were to minimize this tab and run another app, the app would not even load, because all resources have been assigned to Instagram. This is where an OS comes in (Resource Management).
OS acts as an Interface
What does that mean?
Let’s just say you go to a restaurant, and go to the reception and ask for your food package. The cashier goes into the kitchen, and allocates the package and gives it to you. Here, the cashier acts as the interface between you and the package. Similarly, the person at the restraunt acts as the user app, and the OS is the cashier, and the OS allocates resources (GPU, CPU, Memory etc) just like the food to a user app.
Another problem with not having OS?
Memory/resource management becomes manual. This is obvious. Since if you don’t have an OS, and all resources are automatically getting allocated to the app, the developer needs to write code to also manage memory and resources for the app, which is a ridiculously hard process, and also, in larger codebases, this process might make the app not work in different architectures, youll also need to build your own security mechanisms etc, which can be done by an OS itself. Essentially, not having an OS makes the app extremely bulky.
Isolation & Protection:
Let’s say you have 2 apps running. Without an OS, there is a chance that even despite both apps have memory allocated to them and are running, there are chances of memory overwriting from one app to the other, which violates security practices.
An OS provides isolation and does not allow any form of memory overwriting due to its security systems.
It essentially also helps hide the underlying complexity of the hardware.
Types of OS:
Goals of an OS:
Maximum CPU utilization - For eg if you have processes P1 P2 P3 and P4, and P1 has hypothetically taken all resources for it to run, let's just say there’s a 20-minute pause on process P1. You wouldn't want the CPU to then remain idle, instead, work on running P2 P3 P4.
Process Starvation: Let’s just say a P1 was to run a while loop forever, that would hypothetically take up all the resources due to it running forever, which would mean the other processes would just never run because this runs forever. This needed to be addressed.
High-Priority Execution: Let’s just say there were processes P1, P2 and P3 running taking up majority of the resources, and you suddenly need to run a process P4 which lets just say is of bvery high importance, like an antivirus scanning your computer. The OS should be able to handle and allow the running of this important process above the others.
Types:
- Single Process OS: You can execute only 1 job on one OS.
Only when P1 finishes, only then P2 begins.
No max CPU utilization
Does suffer from process starvation.
No high-priority jobs can be executed.
Eg: MS-DOS
- Batch Processing OS:
In a batch processing operating system, processes are typically submitted to the system by the users in the form of job control language (JCL) statements or job control cards. These statements contain information about the job, such as the program to be executed, the input data required, and the desired resources.
The operator's role in a batch processing system was primarily to organize and schedule the jobs. The operator would receive the job submissions and sort them based on various criteria, such as priority, resource requirements, or submission time. The sorting was done to optimize resource utilization and ensure efficient execution of jobs.
These processes were then executed each by the CPU one by one despite being sent in batches. Once again,
No max CPU utilization
Does suffer from process starvation.
However, sorting on the operator level does happen, but any sudden operations to overtake the current operation still won't happen.
Eg: ATLAS
- MultiProgramming OS
In a multiprogramming operating system, the focus is on maximizing the utilization of the CPU by allowing multiple programs or processes to reside in main memory simultaneously. This differs from batch processing, where only one job or program is executed at a time.
In a multiprogramming system, the operating system divides the available memory into partitions or segments, and each partition can hold one program. The programs are loaded into memory and assigned to these partitions, and the CPU is shared among them. The operating system uses scheduling algorithms to determine which program should execute on the CPU at any given time.
The key idea behind multiprogramming is to keep the CPU busy by switching between programs whenever one is waiting for input/output (I/O) operations to complete. While one program is waiting for I/O, the CPU can be allocated to another program that is ready to execute. This overlapping of CPU and I/O operations helps in maximizing the overall system throughput and resource utilization.
Context Switching:
Let’s take an example. Let’s say youve opened your physics textbook, and a certain page on it. You decide to mark that page, and then close the book and then open a chem book because you want to study chem, and mark the page youre studying and then close the chem book too, and open the physics textbook where you previously left it at, and you know where you left it at because of the mark.
Similarly, when one process goes into for eg: I/O operations, the current state of it would get stored in a data structure called the Process Control Block. And this state can be restarted where it got left off at from when the P2 halts, and we come back to P1.
Eg: THE
- Multitasking OS:
In multitasking OS, this is designed to allow multiple tasks or processes to run concurrently on a single computer system. It enables the execution of multiple programs simultaneously, providing the illusion of parallelism and allowing users to work on different tasks concurrently.
In a multitasking system, the operating system uses scheduling algorithms to determine how CPU time is allocated among the running processes. The scheduler assigns a time slice or quantum to each process, allowing it to execute for a certain duration before switching to another process. This time-sharing approach gives the appearance of simultaneous execution and ensures fair utilization of CPU resources among the active tasks.
Also, if an urgent process comes in to be run, like an antivirus check, due to the presence of context switching, that process would be possible to run immediately before coming back to the previous process running.
Eg: CTSS
- MultiProcessing OS:
A multiprocessing operating system is designed to utilize multiple processors or CPU cores to execute tasks concurrently. It focuses on parallel execution of processes or threads across multiple processors, allowing for increased computational power and throughput.
In a multiprocessing system, the operating system manages the allocation and scheduling of processes or threads across the available processors. It distributes the workload among the processors to balance the computational load and maximize resource utilization. The operating system may use different scheduling algorithms to determine which processes or threads should be assigned to which processor.
And also, if one CPU gets faulty, the others would still be working, which is not available in the other types of OS.
Eg: Windows
- Distributed OS:
In a distributed OS, you have an OS with several CPUs, and each of these processes can be assigned to any one of these CPUs.
It manages a network of interconnected computers or devices as if they were a single, unified system. It allows these computers to work together and share resources, such as processing power, storage, and data, while providing a consistent and transparent experience to users and applications.
Cloud Computing: In cloud computing, distributed operating systems manage a large number of computers and storage systems that are connected together. They ensure that different users and companies can store their files and run their programs on these computers without any conflicts. The distributed operating system handles tasks like resource allocation (giving each user the right amount of space and computing power), managing security to keep data safe, etc
Data Centers: Large companies and organizations often have data centers comprising numerous servers and storage systems. A distributed operating system can be employed to manage these resources efficiently, distributing tasks across multiple servers and ensuring high availability, load balancing, and fault tolerance. It allows users to access data and applications stored in the data center seamlessly.
Eg: Apache Hadoop
- RTOS - Real-Time Operating System
Used when error-chance needs to be next to 0. Precise timing, control, responsiveness, etc is very critical, for example, medical devices, Flight Control System (Air traffic Control), nuclear plants, etc. The operating systems fulfilling these purposes are called RTOS. Eg: FreeRTOS