Sonia Manoubi
crunchcrunch

crunchcrunch

[ Devops : Back to Basics ] : Operating systems

This article is part of a serie called [ Devops : Back to Basics ] where i document what i'm learning on my journey to become a Devops Engineer from my current position as a Backend Engineer.

Definition

An operating system (OS) is the whole package that manages out computer's resources and lets us interact with it.

There are two main parts in an OS :

  • the User space
  • the Kernel space

untitled (3).png

The Kernel is the main core of an OS, it talks directly to our hardware and manages our system resources.

As users, we don't interact with the kernel directly, instead we interact with the second part of the OS: the User space. The User space is made with everything outside the kernel like system programs and user interfaces.

There are hundred of OS, but i will focus on Linux which is an open-source OS, widely used in business infrastructure and also in the consumer space.

First, let's focus on the basics of the kernel.

Kernel basics

File Management :

The kernel takes care of file storage and file management

Process Management :

A process is a program in execution. We use many programs at the same time. The kernel manage the order to run those processes, how long they run, how many ressources they take ...

Memory Management :

The kernel optimizes memory usage and makes sure our applications have enough memory to run.

Input / Output (I/O) management :

This is how the kernel talks to external devices like disks, keyboards, mouse, audio devices...

I/O management is anything that can give us input, or that we can use for output of data.

User Space

The User space is everything outside the kernel.

These are programs that the user can interact with such as text editors, music players, system settings, user interface ...

There are two ways to interact with an OS in the user space : with a shell or with a graphic user interface (GUI).

Shell : A program that interprets text commands and sends them to the OS to execute.

Process Management

Process : a program that's executing, like our internet browser or text editor.

Program : an application that we can run, like Chrome.

Note the difference here.

We can have many processes of the same program running at the same time.

When we want to run our programs, we have to dedicate ressources to them like RAM and CPU.

But we only have a finite amount of resources and we want to be able to run multiple programs.

The kernel has to manage our resources efficiently so that all the programs we want to use can be run. The kernel doesn't just dedicate all of our computer's resources to one process. Our system is actually constantly running multiple processes.

When a program wants to run, a process needs to be created for the execution of that program. This process needs to have hardware resources like RAM and CPU.

The kernel has to schedule time for the CPU to execute the instructions in the process. But there is only one CPU and many processes, so how is the CPU able to execute multiple processes at once ?

Actually, it executes processes one by one through something known as a time slice.

Time slice : a very short interval of time that gets allocated to a process for CPU execution.

To the human eye, it looks like it runs at the same time.

The kernel creates processes, efficiently schedules them, and manages how processes are terminated.

untitled (2).png

Memory management

When a process runs, it needs CPU time but also memory.

When processes are running, they have to take up space in memory so that the computer can read and load them quickly.

However, compare to our hard disk drives, memory comes in smaller quantities so to give us more memory than we physically have, we use something called virtual memory.

Virtual memory : the combination of hard drive space and RAM that acts like memory that our processes can use.

When we execute a process, we split the data of our program in chunks called pages.

We store these pages in virtual memory.

If we want to read and execute these pages, they had to be sent to physical memory or RAM.

Why don't we just store the entire program in RAM so we can execute it quickly ?

You could, if it's small enough, but for large applications it would be wasteful.

When we store our virtual memory on our hard drive, we call the allocated space Swap space.

I/O management

Another task that the kernel is responsible for is the input and output devices management.

I/O devices: Devices that perform input and output

These includes our monitor, mouse, keyboard, speakers, hard drive, headsets, webcam ...

There I/O devices are all managed by the kernel.

The kernel has to be able to load up drivers that are used so we can recognize and speak to these different types of hardware. When the kernel is able to start the drivers to communicate with hardware, it also manages the transfer of data in and out of the devices.

The devices also need to communicate with each other. The kernel handles all the inter-communication between devices. It also figures out what the most efficient method of transfer is and it tries it's best to make sure our data doesn't have errors during process.

Logs

Logs: Files that record system events on our computer, just like a system's diary.

Our computer will record events like when it was turned on, when a driver was loaded and even when something isn't working in the form of error messages.

In all operating systems, logs are kept so we can refer back to them when we need to find out something that happened. But logs can be hard to navigate because our computer will essentially record everything !

Boot process

When we start a computer, we use the term boot.

For most OS, the boot process follows a general pattern much like how we have different cars start up in the same way.

BIOS (Basic Input Output System) / UEFI (replaces BIOS since 2006) : a low-level software that initializes our computer's hardware to make sure everything is good to go.

The POST (Power-On Self Test) performs a series of diagnostic tests to make sure that the computer is in proper working order.

Next, a boot device will be selected.

Bootloader : a small program that loads the operating system

One our computer finds a bootloader on a device in the listed order, it'll start to execute this program.

This will start to load a larger and more complex program and eventually loads our OS.

Once the bootloader loads up our OS, our kernel gets loaded. The kernel controls access to our computer's resources, it also loads up drivers and more so our hardware can talk to our software.

boot.png

Conclusion

That's it !

Don't hesitate to comment to point out some mistakes or some precisions.

As i said in the beginning, i am still studying these concepts :)

See you in the next one !

Did you find this article valuable?

Support Sonia Manoubi by becoming a sponsor. Any amount is appreciated!

Learn more about Hashnode Sponsors
Share this