An open API service indexing awesome lists of open source software.

https://github.com/aminkhani/os

Operating System (OS) Tutorial
https://github.com/aminkhani/os

application computer-science hardware operating-system os tutorial

Last synced: 4 months ago
JSON representation

Operating System (OS) Tutorial

Awesome Lists containing this project

README

          



LinkedIn Badge

Gmail Badge


Telegram Badge


Instagram Badge


Github Badge





Operating System (OS) Tutorial






🐛Report Bug
.
❓Ask Question
.
👍Like the repo
.
👎Dislike the repo




> **Note**
>
> 📣 You can help to improve this repo, by giving me a **⭐star⭐** and **❤️following me❤️**

Contents


Why Study Operating Systems?

- **Modern computer** consists of one or more **[processors](#3-processor)**, some **[main memory](#7-memory)**, **disks**, **printers**, a **keyboard**, a **mouse**, a **display**, **network interfaces**, and various other **input/output devices**. All in all, a **complex system**. If every application programmer had to understand how all these things work in detail, no code would ever get written. Furthermore, managing all these components and using them optimally is an **exceedingly challenging job**. For this reason, computers are equipped with a layer of **software** called the **operating system**.

- **Simply because**, as almost **all code runs on top of an operating system**, knowledge of **how operating systems work** is **crucial** to **proper**, **efficient**, **effective**, and **secure** **programming**.

- Understanding the **fundamentals of operating systems**, how they drive computer hardware, and what they provide to applications is not only essential to those who program them but also highly useful to those who **write programs on them and use them**.

Operating System Definition and Function

- In the **Computer System** (comprises of **Hardware** and **Software**), **Hardware** can only understand **machine code** (in the form of **0** and **1**) which doesn't make any sense to a naive user. We need a system which can act as an **intermediary** and manage all the **processes** and **resources** present in the system.




- An **Operating System** can be defined as an **interface between user and hardware**. It is **responsible** for the **execution** of all the **processes**, **Resource Allocation**, **[CPU](#4-cpu-central-processing-unit) management**, **File Management** and many other tasks.

- The **purpose** of an operating system is to **provide an environment** in which a user can **execute programs** in **convenient and efficient manner**.

Structure of a Computer System

- ### A Computer System consists of:
- #### Users
- People who are using the computer.
- #### Application Programs
- Compilers, Databases, Games, Video player, Browsers, etc.
- #### System Programs
- Shells, Editors, Compilers, etc.
- #### Operating System
- A special program which acts as an interface between user and hardware.
- #### Hardware
- CPU, Disks, Memory, I/O Devices ,etc.


What Does an Operating system Do?

#### 1. Process Management
#### 2. Process Synchronization
#### 3. Memory Management
#### 4. CPU Scheduling
#### 5. File Management
#### 6.Security

Operating Systems - History

- #### 1945 – 1955 : The First Generation, Vacuum Tubes and Plugboards

- #### 1955 – 1965 : The Second Generation, Transistors and Batch Systems

- #### 1965 - 1980 : The Third Generation, ICs and Multiprogramming
- #### 1980 - Present : The Fourth Generation, Personal Computers
- #### 1990 - Present : The Fifth Generation, Moblie Computets




Basics of Operating System

- Some **basic knowledge of the structure of Computer System** is **required** to **understand how Operating System works**.

- **Operating system** is intimately tied to the **hardware** of the computer it runs on. It **extends** the **computer’s instruction set** and **manages its resources**.




- The **CPU**, **memory**, and **I/O devices** are all connected by a **system bus** and communicate with one another over it

## 1. Transistor
- A **transistor** is a **[semiconductor device](https://en.wikipedia.org/wiki/Semiconductor_device)** used to **amplify** or **switch electrical signals** and **power**.

- A **transistor** is a **binary switch** and the **fundamental building block** of **computer circuitry**.
- The **transistor** either **prevents or allows** **current** to flow through.

- A **single modern CPU** can have **hundreds of millions** or even **billions** of **transistors**.




## 2. Integrated Circuit (IC)
- An **integrated circuit** or **monolithic integrated circuit** (also referred to as an **IC**, a **chip**, or a **microchip**) is a **set of electronic circuits** on one **small flat piece** (or **chip**) of **semiconductor material**, usually **silicon**.

- On which **thousands or millions of tiny** **resistors**, **capacitors**, **diodes** and **transistors** are fabricated.




## 3. Processor
- In **computing** and **computer science**, a **processor** or **processing unit** is an **electrical component (digital circuit)** that **performs operations** on an **external data source**, usually **memory** or some other data stream.

- It typically takes the form of a **microprocessor**. Today, processors use built-in transistors.

- Like a **soul in our body** keeps us alive so that the **processor** does in the computer.
- ### Moore's law:
- **Moore's law**, named after **[Gordon Moore](https://en.wikipedia.org/wiki/Gordon_Moore)**, is the **observation** and **projection** via historical trend that the **number of transistors** in **integrated circuits (IC)**, and therefore processors by extension, **doubles every two years**. The progress of processors has followed Moore's law closely.

- ### Types of Processors:
- **[CPU](#4-cpu-central-processing-unit)**
- **[GPU](#6-graphics-processing-unit-gpu)**
- **[TPU]()**
- **[PPU]()**
- **[SPE or SPU]()**




## 4. CPU (Central Processing Unit)

- A **processor** is any component that processes commands, reads, and writes data. A **CPU** is a **Central Processing Unit**, and the **main processor** in a computer.
- Many different computer components, like hard drives, have processors but the CPU is the most important processor in a computer and controls everything.

- **Central processing units (CPUs)** are the **primary processors** in most computers. They are designed to **handle a wide variety** of **general computing tasks** rather than only a few domain-specific tasks.

- The **CPU** is a **microprocessor**. The **microprocessor** is an **integrated circuit (IC)** that is **made up of millions of transistors**. However, not all **microprocessors are CPUs**. There are **NPUs**, **GPUs** and **APUs** that remove network, graphics or audio processing from the **CPU**.

- The **brain** of the **computer** is the **CPU (Central Processing Unit)**. It **fetches instructions** from **memory** and **executes** them.

- The basic **cycle** of every **CPU** is to **fetch** the **first instruction** from **memory**, **decode** it to **determine its type and operands**, **execute** it, and then **fetch**, **decode**, and **execute subsequent instructions**.
- The cycle is repeated **until** the **program finishes**. In this way, programs are **carried out**.

- All **CPUs contain** some **registers** inside to **hold key variables and temporary results**.

### CPU Structure

- #### Registers
- **Registers** are parts of the **CPU** that can **store data**.

- **Registers** operate a little like **RAM**, but **can’t hold as much data as RAM can**, but they operate considerably **faster**.

- **Most Important Registers**
- **Accumulator (AC)**
- Stores the results of calculations

- **Program Counter (PC)**
- Stores the **address in RAM** of the **next instruction** to be executed.

- **Instruction Register (IR)**
- Stores the address in RAM of the instruction to be processed

- **Memory Address Register (MAR)**
- Stores the address in RAM of the data to be processed

- **Memory Data/Buffer Register (MDR/MBR)**
- Stores the data to be processed

- **I/O Address Register (I/O AR)**
- Stores the address of the I/O device to be accessed

- **I/O Data/Buffer Register (I/O DR/BR)**
- Stores the data to be processed

- **ALU(Arithmetic Logic Unit)**
- The **ALU is the core of the CPU**.

- **ALU** is responsible for performing **arithmetic** and **logical functions** or **operations**. It consists of two subsections, which are:
1. **Arithmetic Section**
- By **arithmetic operations**, we mean operations like **addition**, **subtraction**, **multiplication**, and **division**, and all these operation and functions are performed by **ALU**. Also, all the complex operations are done by making repetitive use of the mentioned operations by **ALU**.

2. **Logic Section**
- By **Logical operations**, we mean operations or functions like **selecting**, **comparing**, **matching**, and **merging** the data, and all these are performed by ALU.

> **Note:** **CPU** may contain **more than one ALU and ALUs** can be used for maintaining timers that help run the computer system.


- **Control Unit (CU)**
- The **control unit decodes** what each **instruction means**, and can then controls how the other components operate.

- when the control unit receives an instruction, which is just a **binary number**, it will then **signal what the ALU and memory** is supposed to do.

- **Memory**
- The **RAM stores** both the instructions that the computer needs to perform, and the data on which to perform it.

- **Buses**
- All of these components are connected together by bundles of wires that are collectively known as buses. So there is a bus to carry data, another for addresses, and another for instructions.

- **Input and Output**
- Additionally, a computer would usually have some input and output devices that can receive external data and then output the results of the calculation. This could be something as simple as a data connection, or something more complicated such as a keyboard and monitor.

> This method of putting together a computer is known as the **[Von Neumann](https://en.wikipedia.org/wiki/Von_Neumann_architecture)** Architecture. It was devised by John von Neumann in about 1945, well before any of the components that would be needed to produce it had actually been invented.





## 5. Microprocessor

- A **microprocessor** is a **computer processor** where the **data processing logic** and **control** is included on a **single integrated circuit (IC)**, or a **small number of integrated circuits**.

- The **microprocessor** contains the **arithmetic**, **logic**, and **control circuitry** **required to perform the functions** of a **computer's central processing unit**.

- The **integrated circuit (IC)** is capable of **interpreting and executing program instructions** and performing arithmetic operations.

- **Microprocessor** is the **latest** form of **processor or CPU**. The microprocessor is a **single-chip circuit integrated** with **all qualities of CPU** with few new circuits. Its processing **speed is greater than CPU**. Today all latest **processor CPUs are a microprocessor**.




### Key Differences between Processor and Microprocessor

1. Processor or CPU is capable of performing all kinds of computing and arithmetic functions while microprocessor deals in BIOS & memory circuits in addition to performing all CPU functions.

2. Microprocessor functions are greater than the processor. In addition to processor qualities, some graphic processor units (GPU), sound cards and internet cards are also included in it.

3. Microprocessor is the latest and upgraded version of processor/CPU.

4. Although microprocessor is the latest and advanced technology but still the main processing function of the computer is controlled by the processor.

5. The new function of audio processing which helps in producing clear audio is stored in a sound card of the microprocessor which was previously not available in the processor.

6. Due to the addition of different processors on a microprocessor, its speed is slower than the processor.

7. CPUs/processors can be microprocessor but all microprocessors are not CPU.

8. CPU is the main part of the computer while the microprocessor is a simple chip on the motherboard.

## 6. Graphics Processing Unit (GPU)
- A **graphics processing unit (GPU)** is a **computer chip** that **renders graphics** and **images** by performing **rapid mathematical calculations**.

- In the early days of computing, the **central processing unit (CPU)** performed these calculations. As more **graphics-intensive applications** were developed, however, their demands put a strain on the **CPU** and **decreased performance**. **GPUs** were developed as a way to offload those tasks from CPUs and to improve the **rendering of 3D graphics**.

- **GPUs** work by using a method called **parallel processing**, where multiple processors handle separate parts of the same task.

- GPUs are fairly similar to CPU architectures. However, CPUs are used to respond to and process the basic instructions that drive a computer, while GPUs are designed specifically to quickly render high-resolution images and video. Essentially, CPUs are responsible for interpreting most of a computer's commands, while GPUs focus on graphics rendering.





## 7. Memory
- **Memory** is the **electronic holding place** for the **instructions** and **data** a computer needs to reach quickly. It's where information is stored for immediate use. Memory is one of the basic functions of a computer, because without it, a computer would not be able to function properly.

- There are technically **two types of computer memory**: **primary and secondary**. The term memory is used as a **synonym** for **primary memory** or as an abbreviation for a specific type of primary memory called **random access memory (RAM)**. This type of memory is located on microchips that are physically close to a computer's **microprocessor**.

- When a program is open, it is loaded from secondary memory to primary memory. Because there are different types of memory and storage, an example of this could be a program being moved from a solid-state drive (SSD) to RAM

- Memory is volatile, which means that data in memory is stored temporarily. Once a computing device is turned off, data stored in volatile memory will automatically be deleted. When a file is saved, it will be sent to secondary memory for storage that are non-volatile.

- The **memory system** is constructed as a **hierarchy of layers**.




- The **top layer** consists of the **registers internal** to the CPU. They are made of the same material as the CPU and are thus just **as fast as the CPU**. Consequently, there is no delay in accessing them. The storage capacity available in them is typically 32 × 32 bits on a 32-bit CPU and 64 × 64 bits on a 64-bit CPU. Less than 1 KB in both cases. Programs must manage the registers (i.e., decide what to keep in them) themselves, in software.

- **Cache memory**, which is mostly **controlled** by the **hardware**. **Main memory** is **divided up** into **cache lines**, typically **64 bytes**, with addresses 0 to 63 in cache line 0, 64 to 127 in cache line 1, and so on. The most heavily used cache lines are kept in a high-speed cache located inside or very close to the CPU. When the program needs to read a memory word, the cache hardware checks to see if the line needed is in the cache. If it is, called a **cache hit** and else, **cache miss**.
- **Cache hits** normally take about **two clock cycles**.

- Cache memory is limited in size due to its high cost. Some machines have two or even three levels of cache, each one slower and bigger than the one before it.



- **Types of Cache**
- **Primary Cache**
- A primary cache is always located on the processor chip. This cache is small and its access time is comparable to that of processor registers.
- **Secondary Cache**
- Secondary cache is placed between the primary cache and the rest of the memory. It is referred to as the level 2 (L2) cache. Often, the Level 2 cache is also housed on the processor chip.

- Main memory is the primary, internal workspace in the computer, commonly known as RAM (random access memory). Specifications such as 4GB, 8GB, 12GB and 16GB almost always refer to the capacity of RAM. In contrast, disk or solid state storage capacities in a computer are typically 128GB or 256GB and higher

- Magnetic storage or magnetic recording is the storage of data on a magnetized medium. Magnetic storage uses different patterns of magnetisation in a magnetizable material to store data and is a form of non-volatile memory. The information is accessed using one or more read/write heads






Operating System Terminology

- ## Interrupts
- An **interrupt** is a **signal** to the **processor** **emitted by hardware or software** indicating an **event** that needs **immediate attention**. Whenever an interrupt occurs, the **controller completes the execution** of the **current instruction** and starts the execution of an **Interrupt Service Routine (ISR)** or **Interrupt Handler**.

- #### Classes of Interrupts
- **Program**
- **Generated** by some **condition** that occurs as a result of an instruction execution, such as **arithmetic overflow**, **division by zero**, **attempt to execute an illegal machine instruction**, or reference outside a user's **allowed memory space**.

- **Timer**
- **Generated by a timer** within the **processor**. This allows the operating system to perform certain functions on a regular basis.


- **I/O**
- **Generated by an I/O controller**, to signal normal completion of an operation or to signal a variety of error conditions.

- **Hardware Failure**
- **Generated by a failure** such as **power failure** or **memory parity error**.




Types of Operating Systems

- **Operating System** is a well-organized collection of programs that manages the computer hardware. It is a type of **system software** that is responsible for the smooth functioning of the computer system.






Batch Operating System

- In the **1970s**, **Batch processing** was very popular. In this technique, **similar types of jobs** were **batched together** and executed in time.

- This type of **operating system** **does not interact with the computer directly**.




- In **Batch operating system**, **access** is given to **more than one person**; they submit their respective jobs to the system for the execution.

- The system put all of the jobs in a **queue** on the basis of **first come**, **first serve** and then executes the jobs **one by one**. The users collect their respective output when **all the jobs** get executed.

- The **purpose** of this operating system was mainly to **transfer control** from one job to another as soon as the job was completed.


Multiprogramming Operating System

- A **Multiprogramming Operating System** **runs multiple programs** on a **single processor**.

- **Multiprogramming** is an **extension** to **batch processing** where the **CPU** is always **kept busy**. **Each process** needs two types of **system time**:
1. **CPU time**
2. **I/O time**




- In a **multiprogramming environment**, when a process does its I/O, The CPU can start the execution of other processes. Therefore, **multiprogramming** **improves** the **efficiency** of the system.

Multiprocessing Operating System

- In **Multiprocessing**, **Parallel computing** is achieved. There are **more than one processors** present in the system which can execute more than one process at the same time. This will increase the throughput of the system.












Multitasking Operating System

- The **multitasking operating system** is a **logical extension of a multiprogramming system** that enables **multiple programs** simultaneously. It allows a user to perform more than one computer task at the same time.

- While a **multiprogramming operating system** allows **more than one program** to **run** simultaneously using a **single CPU**, a **multitasking operating system** allows **multiple processes** or **tasks** to be **executed** at the same time utilizing multiple CPUs.










- In **preemptive multitasking**, the **operating system** can initiate a context **switching** from the running process to another process. In other words, the operating system **allows stopping the execution of the currently running process and allocating the CPU** to some other process.

- In **cooperative multitasking**, the operating system never initiates context switching from the running process to another process. A context switch occurs only when the processes voluntarily yield control periodically or when idle or logically blocked to allow multiple applications to execute simultaneously. Also, in this multitasking, all the processes cooperate for the scheduling scheme to work.


Network Operating Systems

- An **Operating system**, which includes **software** and **associated protocols** to communicate with **other computers** via a **network** conveniently and cost-effectively, is called **Network Operating System**.




- In this type of operating system, **network traffic reduces** due to the **division between clients and the server**.

- This type of system is **less expensive** to **set up** and **maintain**.

- In this type of operating system, the **failure of any node** in a system affects the whole system.

- **Security and performance are important issues**. So trained network administrators are required for network administration.


Real Time Operating System

- In **Real-Time Systems**, each job **carries a certain deadline** within which the job is supposed to be **completed**, **otherwise**, the huge loss will be there, or even if the result is produced, it will be completely useless.




- The **Application of a Real-Time system** exists in the case of **military applications**, if you want to drop a missile, then the missile is supposed to be dropped with a certain precision.




- Easy to layout, develop and execute real-time applications under the real-time operating system.

- In a Real-time operating system, the maximum utilization of devices and systems.

- Real-time operating systems are very costly to develop.

- Real-time operating systems are very complex and can consume critical CPU cycles.

Time-Sharing Operating System

- In the **Time Sharing operating system**, computer resources are allocated in a time-dependent fashion to several programs simultaneously. Thus it helps to provide a large number of user's direct access to the main computer.

- It is a **logical extension of multiprogramming**. In time-sharing, the CPU is switched among multiple programs given by different users on a scheduled basis.

- A time-sharing operating system allows many users to be served simultaneously, so sophisticated CPU scheduling schemes and Input/output management are required.

- Time-sharing operating systems are very difficult and expensive to build.

- The time-sharing operating system provides effective utilization and sharing of resources.

- This system reduces CPU idle and response time.

- Data transmission rates are very high in comparison to other methods.

- Security and integrity of user programs loaded in memory and data need to be maintained as many users access the system at the same time.


Distributed Operating System

- The Distributed Operating system is not installed on a single machine, it is divided into parts, and these parts are loaded on different machines. A part of the distributed Operating system is installed on each machine to make their communication possible. Distributed Operating systems are much more complex, large, and sophisticated than Network operating systems because they also have to take care of varying networking protocols.

- The distributed operating system provides sharing of resources.

- This type of system is fault-tolerant.

- Protocol overhead can dominate computation cost.