Welcome to Operating Systems (OS)!


In today’s computer-driven world, who hasn’t used a computer? Yet, how many of us truly ponder how this device operates and interacts with it? ……It’s time to dive into the realm of the operating system.

Welcome to the world of Operating Systems (OS)!

What is Operating System (OS):

Operating System (OS) is system software that orchestrates computer hardware and software resources.

Each operating system is distinguished by a unique set of characteristics and functions. They differ significantly in how they manage resources and offer services to users.

Example of Different Operating Systems

Operating system (OS) goals:

Make the computer system convenient to use:

It provides essential services for computer programs, acting as the crucial interface between hardware components and software applications.

efficiently use the computer hardware & Execute user programs:

The OS creates an environment for programs to execute and effectively manages the system’s resources. This includes critical tasks like memory management, process scheduling, file handling, input/output operations, and providing a user-friendly interface for interaction with the computer.

In general, any action you take as a user, such as pressing a keyboard, is translated by the operating system into instructions for the software.


Processes VS Operating system (OS)

The operating system (OS) manages all operations and resources on a device, including handling processes.

The OS manages resource allocation for these processes such as CPU access, memory, files, and input/output.

The system controls the execution and resource allocation for each process, ensuring efficient operation without conflicts with other processes.

Process: is a program in execution.

Before talking about processes, several words have s seem similar, they represent distinct concepts within OS, such as

Main Memory ≠ RAM:

→ “Main memory” refers to the primary storage used by a computer to hold data and programs that are currently being executed.

→ “RAM” (Random Access Memory) is a type of main memory that allows quick access and serves as the workspace where programs run and data is temporarily stored during computer operation.

Process ≠ Program:

→ A “program” is a set of written instructions or code that performs a specific function.

→ A “process” is the execution of a program, where the program is loaded from storage into memory and executed on the CPU.

CPU ≠ Processor:

→ The “CPU” (Central Processing Unit) is the primary component in a computer responsible for performing arithmetic, logic operations, and executing instructions.

The “processor” refers generally to the chip or electronic circuit that contains the CPU along with other components like the control unit, cache, etc.

& There is a deep difference between the core and the processor:

→ The “processor” generally refers to the entire chip that contains various components like the arithmetic logic unit (ALU), control unit, cache, etc.

→ The “core” refers to the individual processing units within a processor that can independently execute instructions. A processor can have multiple cores, allowing it to handle multiple tasks simultaneously.


The memory layout of a process consists of parts:

Imagine running a video game on your computer. This game is a program. When you start running the game, it occupies a specific space in the computer’s memory. This space is made up of different parts:

1. Text Section:
 — This is where the commands and codes that make the game work are stored. For example, the instructions that tell the game how characters appear on the screen are stored here.

2. Data Section:
 — It contains general variables accessible to different parts of the game, like the number of lives or points you’ve earned.

3. Heap:
 — This area dynamically allocates memory during the game for anything that needs storage, like adding a new character to the gameplay.

  1. Stack:
     — It’s used to hold temporary information, such as function-related data, and local variables, and navigate back and forth within the game. For instance, when you move to a new level, this area might remember where to return if you fail at a challenge.

Example: Let’s say you have a game that keeps track of your earned points. In the data section, there’s a variable called “Player Points” stored. Whenever you gather new points, this variable in the data section gets updated.


Process State:

Let’s consider a printing program as an example. When you print a document, the printing process follows a similar pattern in different states:

1. New State:
 — When you open the printing program and prepare the document you want to print, the program is in the “new” state.

2. Running State:
 — Upon hitting the print button, the program starts executing commands to print the document. Here, the program is in the “running” state, actively performing its task.

3. Waiting State:
 — You might experience some delay while waiting for a paper change or due to a printer malfunction. During this time, the program is in the “waiting” state for a specific event.

4. Ready State:
 — After fixing the issue or changing the paper, the program is ready to continue printing. This state is similar to being “ready” to resume the task.

5. Terminated State:
 — When the printing process successfully finishes, and the document is fully printed, the program enters the “terminated” state. Here, the document is printed, and the process is completed successfully.

This example demonstrates how the process transitions through different states during a printing operation, similar to various operational tasks on a computer.


Process Control Block (PCB):

PCB, also called Task Control Block, is the Information associated with each process.

Let’s consider an example related to playing a video file on a computer:

1. Process State:
 — When you start playing a video file, the media player program is in the “running” state.

2. Program Counter:
 — It points to the current position in the video file being played, such as the current frame or the elapsed time in the video.

3. CPU Registers:
 — Contains information about video encoding, translations, and any available subtitles or comments.

4. CPU Scheduling Information:
 — Aids in scheduling various tasks on the device, like playing the video while running other applications.

5. Memory-Management Information:
 — Contains details about the allocated space to run the video and areas designated for temporary data storage.

6. Accounting Information:
 — Holds details about the resources utilized during video playback, such as CPU consumption and memory usage.

7. I/O Status Information:
 — Includes details about the displayed video quality, audio devices used, or any audiovisual output-related details.

These pieces of information represent a part of the Process Control Block (PCB), helping manage video playback and ensuring efficient resource usage to provide a seamless viewing experience for the user.


Process Scheduling:

How does the system handle process scheduling, managing diverse applications and their execution?????????!!!!!!!!

scenario → where you’re working on your computer, running multiple applications simultaneously like a word processor, media player, and a graphic design tool. Let’s explore how the system manages these applications and process scheduling:

1. Process Scheduling:— Core Functionality: Process scheduling ensures that at least one process is running at all times, optimizing CPU utilization by allowing multiple processes to share time on the CPU.

- Scheduler Management: The scheduler chooses among available processes for program execution on the core of the computer.

- Single-Core Systems: Only one process can run at a time, meaning other processes have to wait for the current process to finish execution before they can be scheduled.

- Multi-Core Systems: Multiple processes can run simultaneously on different cores, allowing parallel execution of multiple processes.

2. Types of Processes:— I/O-Bound Processes: Spend most of their time performing I/O operations like file read/write or network communication.

— CPU-Bound Processes: Spend most of their time in computations, resulting in longer periods of CPU usage.

4. Scheduling Queues:— Ready Queue: Contains all processes residing in the main memory, waiting to execute. The header of the ready queue includes pointers indicating the first processes in the list.

Wait Queue: Holds processes waiting for specific events like completion of I/O operations.

This scenario elucidates how the system handles process scheduling, managing diverse applications and their execution based on system priorities and the requirements of various applications.


Process Swapping:

a memory management scheme in which any process can be temporarily swapped from main memory to secondary memory (hard disk) so that the main memory can be made available for other processes to go to the processor.

Scenario:
Imagine you’re working on a computer system with limited RAM, and you’ve opened several resource-intensive applications such as video editing software, a gaming application, and a virtual machine for software development, all running simultaneously.

Swapping Implementation:

1. Resource Consumption:

These applications consume a substantial amount of RAM, quickly filling up the available memory space.

2. Swapping Mechanism:— Swap-Out Operation: The operating system identifies inactive or less frequently used parts of these applications and temporarily moves them from the RAM to the hard disk to free up space. For instance, portions of the virtual machine or older frames in the video editing software could be moved.

— Swap-In Operation: When you switch back to any of these applications, the system retrieves the required data from the hard disk to the RAM, seamlessly continuing the application’s operation.

3. Swap Space: The area on the hard disk where these swapped-out data and application portions are stored temporarily is known as swap space.

4. Benefits of Swapping:— Optimized RAM Utilization: Swapping optimizes the usage of limited RAM by transferring less actively used portions of applications to the hard disk, making room for more critical or actively used parts in the RAM.

5. User Experience Impact:— Possible Delay: Swapping might cause a slight delay when switching between these resource-heavy applications since the system needs time to restore the data from the hard disk to the RAM before smoothly resuming the application’s operation.


Process Termination:

This example illustrates how the operating system handles process termination in the context of an interrupted file download from the internet, highlighting the termination of subprocesses and the potential creation of zombie processes if their termination statuses are not collected.

Let’s say you’re downloading a large file using a download manager or browser. During the download process, if your internet connection suddenly fails or disconnects, it can illustrate various aspects of process termination in an operating system.

1. Download Process (Main Process):
 — Initiating the download via a browser or download manager involves multiple subprocesses responsible for downloading different parts of the file.

2. Subprocesses (Child Processes):
 — Each subprocess is responsible for downloading a specific part of the large file. These subprocesses operate as children to the main download process.

3. Termination Scenario:
 — If the internet connection is interrupted during the download, some subprocesses might terminate unexpectedly, demonstrating concepts of process termination.
 — Subprocesses that fail to complete (due to the interruption) may terminate abruptly, signaling the operating system to end their execution.

4. Zombie Process Scenario:
 — If subprocesses complete their download but the main process (browser or download manager) fails to collect their termination status, zombie processes might exist in the system.
 — These zombie processes have finished downloading a part of the file but remain in the system’s process table due to their termination status not being collected by the main process.


→Reference book: Operating System Concepts, ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, Pluribus Networks, Ninth Edition, John Wiley & Sons, Inc, 2013