Introduction to Operating Systems


Module 1

Unit 1: Introduction to Operating Systems

1. Generations and Evolution of Operating Systems


2. Types of Operating Systems


3. Operating System Services

Pasted image 20240802123603.png

Pasted image 20240802124125.png

Operating systems provide various services to both the users and the system itself. These services are crucial for managing hardware resources and providing an interface for user interactions.

  1. Program Execution

    • The OS loads the program into memory, initialises the necessary resources, and begins its execution. It handles the scheduling of processes, manages the execution flow, and ensures that processes can be suspended or resumed as needed.
  2. I/O Operations

    • Operating systems manage input and output devices, such as keyboards, monitors, printers, and disk drives. This involves:
      • Device Communication: OS sends and receives data from devices.
      • Buffering: Temporarily storing data while it is being transferred between devices or between a device and memory.
      • Caching: Storing frequently used data in faster storage (cache) for quick access.
      • Spooling: Storing data for devices like printers that cannot handle interleaved data streams.
  3. File System Manipulation

    • OS provides services for file creation, deletion, reading, writing, and permissions management. Key aspects include:
      • File Attributes: OS stores metadata about files, such as size, type, and permissions.
      • Directory Structure: Organises files in a hierarchical structure, allowing efficient navigation and management.
      • File Access Methods: Sequential and direct (or random) access, depending on the file type and application needs.
  4. Communication

    • OS manages communication between processes, either on the same system or across different systems. This can include:
      • Inter-process Communication (IPC): Mechanisms like pipes, shared memory, message queues, and sockets that allow processes to exchange data.
      • Network Communication: Protocols and services for data exchange over networks, including TCP/IP stack management.
  5. Error Detection and Handling

    • OS continuously monitors the system for errors, such as hardware failures, software bugs, and resource allocation issues. It provides mechanisms for:
      • Error Logging: Recording error events for analysis and debugging.
      • Error Handling: Taking corrective actions, such as terminating a process, retrying operations, or notifying the user or administrator.
  6. Resource Allocation

    • OS manages hardware resources like CPU, memory, disk space, and peripheral devices. It allocates resources to processes and ensures fair and efficient use, preventing conflicts and ensuring system stability.
  7. Protection and Security

    • OS provides mechanisms to protect data and resources from unauthorised access. This includes:
      • User Authentication: Ensuring that only authorised users can access the system.
      • Access Control: Defining permissions for users and groups to access files and resources.
      • Data Encryption: Protecting data during transmission and storage.

4. System Calls

Types of System Calls

  1. Process Control

    • Examples: fork(), exec(), exit(), wait()
    • Functions: Create and terminate processes, load and execute programs, and manage process synchronisation.
  2. File Management

    • Examples: open(), read(), write(), close(), delete()
    • Functions: Handle file creation, deletion, reading, writing, and closing. Also, manage file attributes and metadata.
  3. Device Management

    • Examples: ioctl(), read(), write()
    • Functions: Control device-specific operations, such as setting device parameters, and managing I/O operations for devices like disk drives and printers.
  4. Information Maintenance

    • Examples: getpid(), alarm(), sleep(), time()
    • Functions: Provide information about the system and processes, set timers and alarms, and manage system time.
  5. Communication

    • Examples: pipe(), shmget(), msgsnd(), msgrcv(), socket()
    • Functions: Facilitate communication between processes, either within the same system or across networked systems. This includes shared memory, message passing, and socket communication for network connections.

System Call Mechanism

Examples of Common System Calls

  1. fork(): Creates a new process by duplicating the calling process. The new process is called the child process.
  2. exec(): Replaces the current process image with a new process image, effectively running a new program.
  3. open() and close(): Open and close files, returning a file descriptor used for subsequent operations.
  4. read() and write(): Read from and write to files or devices.
  5. ioctl(): Performs device-specific operations that are not covered by standard system calls.
  6. pipe(): Creates a unidirectional data channel that can be used for IPC.
  7. shmget() and shmat(): Allocate and attach shared memory segments for IPC.

5. Structure of an Operating System

A bit in depth about the structure of an OS.

Pasted image 20241123201644.png

Category Description
User Interface (CLI / GUI)
System Utilities File Management Tools: Copying, moving, and deleting files.
Disk Management Tools: Formatting disks, checking disk integrity, and partitioning.
System Monitoring Tools: Programs that monitor system performance and resource usage.
Backup and Recovery Tools: Utilities for backing up data and recovering from system failures.
System Libraries File Management Tools: Utilities for copying, moving, and deleting files.
Disk Management Tools: Utilities for formatting disks, checking disk integrity, and partitioning.
Networking: Managing network communication and protocols.
Utility Functions: Providing mathematical calculations, data manipulation, etc.
Middleware Database Middleware: Facilitates interaction between applications and databases.
Message-Oriented Middleware (MOM): Enables communication between distributed systems.
Web Middleware: Provides services for web applications, such as web servers and application servers.
Device Drivers
Kernel * Process Management
* Memory Management
* File System Management
* Device Management
* Security and Access Control
Bootloader
Hardware

1. Kernel

The kernel is the core component of an operating system. It acts as a bridge between applications and the hardware. The kernel is responsible for:

2. User Interface

The user interface is what allows users to interact with the computer. There are two main types of user interfaces:

3. System Libraries

System libraries provide a set of standard functions and routines that programs can use to perform common tasks without needing to interact directly with the kernel. These libraries facilitate:

4. System Utilities

System utilities are programs that perform system maintenance and configuration tasks. These include:

5. Device Drivers

Device drivers are specialized programs that allow the OS to communicate with hardware devices. Each hardware component (e.g., printers, graphics cards, network adapters) requires a driver to function correctly. Drivers translate general OS commands into specific instructions for the hardware.

6. Shell

The shell is a command interpreter that provides a user interface for access to the services of the operating system. In UNIX and Linux systems, the shell can be either a command-line interface (like Bash or Zsh) or a graphical interface.

7. Bootloader

The bootloader is a small program that loads the operating system into the computer's main memory (RAM) when the system is powered on. It is the first software that runs when a computer starts and is responsible for initializing the system hardware and starting the kernel.

8. Middleware

Middleware is software that lies between the OS and the applications, facilitating communication and data management. It includes:

9. System Call Interface

The system call interface provides the means for user programs to communicate with the kernel. System calls are functions provided by the OS that programs can call to request services such as process creation, file operations, and communication.

10. Virtual Machines

Some modern operating systems support virtualization, allowing multiple operating systems to run on a single physical machine. The OS can manage these virtual environments, each with its own isolated resources


6. Virtual Machine Concept

How Virtual Machines Work

1. Hypervisor

The core technology behind virtual machines is the hypervisor, also known as the virtual machine monitor (VMM). The hypervisor manages the creation, execution, and termination of VMs. There are two types of hypervisors:

2. Virtual Machine Components

Each virtual machine consists of the following components:

3. VM Lifecycle

The lifecycle of a VM includes the following stages:

4. Resource Allocation and Management

The hypervisor manages the allocation of host resources (CPU, memory, storage, network) to the VMs. It ensures that each VM gets its fair share of resources while maintaining isolation between VMs to prevent them from interfering with each other.

5. Isolation and Security

VMs are isolated from each other and from the host system. This isolation ensures that processes running inside one VM cannot affect those in another VM or the host. It enhances security by containing potential threats within individual VMs.

Advantages of Virtual Machines

  1. Resource Optimization: VMs allow multiple operating systems to run on a single physical machine, optimizing hardware usage.
  2. Isolation: VMs are isolated from each other, improving security and stability.
  3. Scalability: Easy to create, modify, and delete VMs based on resource needs.
  4. Flexibility: VMs can run different operating systems and software configurations on the same physical hardware.
  5. Disaster Recovery: VMs can be easily backed up, restored, and migrated, aiding in disaster recovery scenarios.

Example of VM Usage

Diagram

+--------------------------------------------------+
|                  Host Machine                    |
|                                                  |
| +----------------------------------------------+ |
| |               Hypervisor/VMM                 | |
| |                                              | |
| | +--------+   +--------+   +--------+         | |
| | |  VM 1  |   |  VM 2  |   |  VM 3  |         | |
| | |--------|   |--------|   |--------|         | |
| | | vCPU   |   | vCPU   |   | vCPU   |         | |
| | | vRAM   |   | vRAM   |   | vRAM   |         | |
| | | vDisk  |   | vDisk  |   | vDisk  |         | |
| | | vNIC   |   | vNIC   |   | vNIC   |         | |
| | +--------+   +--------+   +--------+         | |
| +----------------------------------------------+ |
+--------------------------------------------------+


7. Case Study: UNIX and Windows Operating Systems

+-----------------+------------------------+------------------------+
|     Feature     |       Unix/Linux       |        Windows         |
+-----------------+------------------------+------------------------+
| Kernel          | Monolithic             | Hybrid                 |
| User Interface  | CLI (Shell), GUI       | GUI                    |
| File System     | Hierarchical (ext4,    | NTFS                   |
|                 | XFS, etc.)             |                        |
| Security        | Strong permissions,    | User Account Control,  |
|                 | multiuser              | Windows Defender       |
| Networking      | Built-in TCP/IP,       | Built-in TCP/IP,       |
|                 | robust server support  | file sharing, remote   |
|                 |                        | access                 |
| Portability     | High (C-based)         | Moderate (x86-based)   |
| Use Cases       | Servers, development,  | Desktops, enterprise,  |
|                 | embedded systems       | gaming, development    |
+-----------------+------------------------+------------------------+

Unix Operating System

History

Architecture

Features

Use Cases


Windows Operating System

History

Architecture

Features

Use Cases

Comparison

Architecture

Features

Use Cases