Unit 1 - Notes

CSE316

Unit 1: Introduction to Operating System

1. Operating System Overview

Meaning and Definition

An Operating System (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. It acts as an intermediary between the user of a computer and the computer hardware.

  • Goal: Execute user programs and make solving user problems easier.
  • Efficiency: Manage computer hardware in an efficient manner.
  • Role: It is a Resource Manager (CPU, Memory, I/O) and a Control Program (controls execution of programs to prevent errors).

Functions of an Operating System

  1. Process Management: Creation, scheduling, termination of processes, and deadlock handling.
  2. Memory Management: Allocation and deallocation of memory space to programs.
  3. File Management: Creating, deleting, and manipulating files and directories.
  4. I/O Management: Hiding peculiarities of specific hardware devices from the user (Device Drivers).
  5. Security and Protection: Protecting data from unauthorized access.
  6. Command Interpretation: Interpreting user commands and acting on them.

Supervisor Mode & User Mode

To ensure the proper execution of the operating system, distinct modes of operation are distinguished to protect the OS from errant users.

  1. User Mode (bit 1):
    • When the computer system is running user applications (like a word processor or web browser).
    • Restricted access to hardware; cannot execute privileged instructions.
    • If a user program attempts a privileged instruction, a hardware trap occurs.
  2. Supervisor Mode (Kernel/System Mode) (bit 0):
    • When the OS code is running (handling interrupts, system calls).
    • Full access to all hardware and memory.
    • Privileged instructions (e.g., controlling interrupts, switching modes, I/O management) can only be executed here.

2. Types of Operating Systems

Evolution of Operating Systems

The OS has evolved through several generations:

  1. Serial Processing: No OS; users interacted directly with hardware via toggle switches.
  2. Simple Batch Systems: Jobs with similar needs were batched together.
  3. Multiprogramming: Keeping several jobs in memory simultaneously.
  4. Time-Sharing: Logical extension of multiprogramming for user interaction.

1. Simple Batch Systems

  • Mechanism: The user prepares a job (program + data + control info) usually on punch cards and submits it to the operator. The operator groups jobs with similar needs into a "batch" and runs them.
  • Characteristics: Transfer of control is automatic via a resident monitor.
  • Disadvantage: CPU is often idle because I/O devices are slower than the processor. Lack of interaction between user and job.

2. Multiprogramming Systems

  • Concept: Increases CPU utilization by organizing jobs so that the CPU always has one to execute.
  • Mechanism: The OS keeps several jobs in memory simultaneously. When one job needs to wait (e.g., for I/O), the OS switches the CPU to another job.
  • Key Requirement: Requires memory management and job scheduling.

A detailed schematic diagram comparing Uniprogramming vs. Multiprogramming memory layouts. The left ...
AI-generated image — may contain inaccuracies

3. Multitasking (Time-Sharing) Systems

  • Concept: A logical extension of multiprogramming. The CPU switches jobs so frequently that users can interact with each job while it is running.
  • Mechanism: Uses Time Quantum (Time Slices). Each user gets a small slice of CPU time.
  • Response Time: The primary goal is to minimize response time.

4. Multiprocessing Systems

  • Systems with two or more processors in close communication, sharing the computer bus, the clock, and sometimes memory and peripheral devices.
  • Types:
    • Symmetric Multiprocessing (SMP): Each processor performs all tasks; all are peers.
    • Asymmetric Multiprocessing: Master-slave relationship. Master processor schedules the slaves.
  • Advantages: Increased throughput, economy of scale, increased reliability (graceful degradation).

5. Distributed Operating Systems

  • A collection of physically separate, possibly heterogeneous computer systems that are networked to provide the users with access to the various resources that the system maintains.
  • Loosely Coupled: Each processor has its own local memory.
  • Goal: Resource sharing, computation speedup (load balancing), reliability.

6. Real-Time Operating Systems (RTOS)

Used when there are rigid time requirements on the operation of a processor or the flow of data.

  • Hard Real-Time: Critical tasks must be completed within a guaranteed time (e.g., flight control). Data stored in ROM; virtual memory usually absent.
  • Soft Real-Time: Critical task gets priority over other tasks, but no absolute guarantee (e.g., multimedia streaming).

3. OS Structure and System Calls

Operating System Structure

  1. Monolithic: The entire OS runs as a single program in kernel mode (e.g., MS-DOS, early Unix). Fast but difficult to maintain.
  2. Layered: The OS is broken into a number of layers (levels). The bottom layer (0) is hardware; the highest (N) is the user interface. Easier to debug.
  3. Microkernel: Moves as much functionality as possible from the kernel into "user space." Communication happens via message passing (e.g., Mach, QNX).

System Calls

System calls provide the interface between a running program and the operating system. They are generally available as assembly-language instructions or high-level API calls (like C standard library).

  • Mechanism: A user program calls a function (e.g., open()) -> Trap to Kernel Mode -> OS executes the instruction -> Return to User Mode.
  • Types of System Calls:
    • Process Control: fork(), exit(), wait()
    • File Management: open(), read(), write(), close()
    • Device Management: ioctl(), read(), write()
    • Information Maintenance: getpid(), alarm(), sleep()
    • Communications: pipe(), shmget(), mmap()

4. Process Management

Process Concept

A process is a program in execution. A program is a passive entity (stored on disk), while a process is an active entity.

  • Components:
    • Text Section: The program code.
    • Program Counter: Current activity.
    • Stack: Temporary data (function parameters, return addresses, local variables).
    • Data Section: Global variables.
    • Heap: Memory dynamically allocated during run time.

Process Life Cycle (Process States)

As a process executes, it changes state.

  1. New: The process is being created.
  2. Ready: The process is waiting to be assigned to a processor.
  3. Running: Instructions are being executed.
  4. Waiting (Blocked): The process is waiting for some event to occur (such as an I/O completion or reception of a signal).
  5. Terminated: The process has finished execution.

A standard 5-state Process State Transition Diagram. Five circles arranged logically: "New" (top lef...
AI-generated image — may contain inaccuracies

Process Control Block (PCB)

Each process is represented in the operating system by a Process Control Block (also called a Task Control Block). It serves as the repository for any information that may vary from process to process.

Contents of PCB:

  • Process State: (New, ready, running, etc.)
  • Program Counter: Address of the next instruction to execute.
  • CPU Registers: Accumulators, index registers, stack pointers (saved when an interrupt occurs).
  • CPU Scheduling Information: Priority, pointers to scheduling queues.
  • Memory-Management Information: Base and limit registers, page tables.
  • Accounting Information: CPU time used, time limits.
  • I/O Status Information: List of I/O devices allocated, list of open files.

A vertical diagram illustrating the structure of a Process Control Block (PCB). It should look like ...
AI-generated image — may contain inaccuracies

Operations on Processes

  1. Process Creation:
    • A parent process creates children processes, which, in turn, create other processes, forming a tree of processes.
    • System call in Unix: fork() creates a new process. exec() is used after a fork to replace the process' memory space with a new program.
  2. Process Termination:
    • Process executes the last statement and asks the OS to delete it (exit()).
    • Resources are deallocated by the OS.
    • A parent may terminate the execution of children via abort() (e.g., if the child has exceeded usage of allocated resources).

Co-operating and Independent Processes

  1. Independent Process:
    • Cannot affect or be affected by the execution of another process.
    • Does not share data with other processes.
  2. Cooperating Process:
    • Can affect or be affected by other processes.
    • Reasons for cooperation: Information sharing, Computation speedup (parallel execution), Modularity, Convenience.
    • Requires Inter-Process Communication (IPC) mechanisms like Shared Memory or Message Passing.