What is an Operating System?: A Beginner's Guide
Tags: computerscience, programming, beginners
Published: 2023-05-22 23:56:09

An `Operating system(OS)` is software that manages resources between computer hardware and software. It acts as an intermediary and allows the user and computer hardware to interact. The Operating System plays an essential role in managing computer resources and enabling the execution of software applications. Just as the name implies, it executes all the operations in a computer.

## How does it work?

The Operating System has a program called `Kernel` which is loaded into the main memory from the storage device, which is either the hard drive or solid-state drive(SSD) when a computer is powered on. The `Kernel` interacts with the computer programs and hardware components including the central processing unit (CPU), memory (RAM), storage devices, input/output (I/O) devices (keyboard, mouse, display), and network interfaces. So when you start a program, the `Kernel` starts the process, allocates CPU resources, and cleans up the resources as soon as you close the program. It provides seamless interaction between hardware and software applications.

Take, for instance, a user needs to use the Chrome browser application on the computer and there’s no operating system. Since software applications cannot interact with the hardware directly, the user has to manually communicate the details of every action to the hardware using code. So in a case where a user wants to run 5 applications at a go, this means that there has to be a written code for each of those applications to interact with the hardware and this can be very tedious and confusing. 

The Operating System takes away all these complexities by acting as the intermediary, thereby allowing software applications to interact with the hardware.  

![An image to show how an operating system works](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fljv1r0ovt8erntqdpn2.png)

## Functions of the Operating System.

The Operating System performs several functions in the computer including the allocation of resources and management. Here are some of the key functions of the OS:

- **Process Management:**  The OS manages CPU resources by allocating CPU memory to a process. A process is an instance of a program running on a computer, this could be opening a new terminal window on your computer or starting your code editor application. Each process has an allocated CPU memory to avoid interfering with other processes.


![Activity monitor for CPU usage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kmfk8pn5rhegsb0vbrg2.png)

_Activity monitor for CPU usage_

- **Memory Management:**  This is the allocation of working memory known as `Random Access Memory(RAM)` to computer programs. You cannot run any program on the computer without RAM allocation for its execution. The RAM memory is limited and if the total RAM required by all the running programs exceeds the available RAM capacity, this causes your computer to lag. The OS solves this problem by swapping memory between computer programs. It clears memory from the inactive program, stores it in the secondary storage which is the hard drive, and then reallocates it back to a new program. This process is called memory swapping, it takes time to swap memories between programs and this might slow your computer down for a while.


![Activity monitor for RAM usage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7en81x4yk993fsqqal90.png)

_Activity monitor for RAM usage_

- **Storage Management:** This is also known as the secondary memory/hard drive and it is used to persist data for long-term storage. When using a code editor like Visual Studio Code, the data you work with, such as code files and project configurations, is loaded into the computer's RAM for quick access. As you make changes, they are saved in memory, allowing you to see immediate results without affecting the actual files on the hard drive. When you close the code editor or explicitly save the files, the data is written and persisted on the hard drive, ensuring your changes are saved for future use. The next time you open the code editor, the data is retrieved from the hard drive and loaded into RAM, enabling you to continue working from where you left off.

**Other functions include:**

- Managing file system

- Managements of I/O devices

- Security and Networking.

## Examples of Operating Systems.

Popular examples of operating systems include:

- Linux
- MacOS
- Windows
- IOS
- Android

## TLDR

An Operating System (OS) is software that manages computer hardware and provides a user-friendly interface for users to interact with the computer. It acts as an intermediary between applications and the underlying hardware, enabling the execution of programs, managing system resources, and providing essential services like file management, memory allocation, and process scheduling. 

The OS controls the flow of data and ensures efficient utilization of resources. Furthermore, it ensures stability and reliability by protecting the system from unauthorized access. 

Windows, macOS, Linux, Android, and iOS are all examples of operating systems, which are each tailored for specific devices and environments.