BCS401 Operating System Semester IV · AY 2025-26 onward
Unit 1 · Introduction & OS Structure

Lecture 4: Time‑sharing systems

Learning outcomes

  • Understand how time‑sharing operating systems provide concurrent interactive use of a computer.

Prerequisites

-- Lecture 1–3 basics: OS as resource manager/service provider, OS services, and OS classification. -- Basic terms: CPU, RAM, disk, I/O, process/program. -- Basic idea of multiprogramming (more than one job/program kept ready to run).

Lecture Notes

Main content

Time-Sharing Systems (and its relation with Multiprogramming)

Learning Focus

Understand what a time-sharing operating system is, how it works using time slicing, and compare time-sharing with multiprogramming in terms of objectives, operation, and resource usage.


1) What is a Time-Sharing System?

A time-sharing system is an operating system approach in which the CPU switches rapidly among multiple users/programs, so each user feels like they have a dedicated computer. This is achieved using time slicing (also called a time quantum), where CPU time is divided into small slices and allocated one by one to runnable tasks.

Key idea:

Time-sharing prioritizes interactive response time (fast feedback) and fairness among users, rather than only maximizing throughput.


2) Multiprogramming — The foundation idea you must know

Multiprogramming is an operating system technique in which multiple programs (processes) are kept in main memory at the same time, and the CPU is switched to another program whenever the current program is waiting for input/output (for example, disk or network). The primary goal is to keep the CPU busy and improve CPU utilization.

Remember this in one line:

Multiprogramming improves CPU utilization; time-sharing improves response time and fairness (built on multiprogramming).

2.1 What multiprogramming tries to achieve

  • Keep CPU busy by switching to another ready job when one job waits for input/output.
  • Increase throughput (more completed work per unit time).
  • Reduce idle CPU time caused by slow input/output devices.

2.2 What it requires internally

  • Multiple jobs/processes present in memory at the same time.
  • Process scheduling to choose the next ready process.
  • Memory management and protection so processes do not interfere with each other.

3) Why Time-Sharing? (Need and Motivation)

  • Interactive users work in short cycles: type → run → see output → correct → run again.
  • Many users can share a costly computer system (lab/server) instead of each needing a separate machine.
  • Time-sharing uses multiprogramming + preemption to keep the system responsive.

4) Core Characteristics of Time-Sharing Systems

4.1 Time Slicing (Time Quantum)

  • CPU time is divided into small slices called quanta.
  • After a quantum ends, the OS performs a context switch to another ready task.
  • This switching happens fast enough that users feel the system is “always responding”.

4.2 Preemptive Scheduling

  • The OS can preempt a running process when its quantum expires.
  • This prevents any single user/program from monopolizing the CPU.
  • Fairness and responsiveness are the main goals.

4.3 Virtual Memory Support

  • Time-sharing systems often support many users at once.
  • Virtual memory helps keep more programs “active” than physical RAM alone would allow.

4.4 Multiuser Isolation & Protection

  • Each user has an independent session/environment.
  • OS provides isolation, protection, and resource management.
  • Typical mechanisms: user IDs, file permissions, process isolation, and quotas.

5) Time-Sharing vs Multiprogramming (Important Exam Question)

Point Multiprogramming Time-Sharing
Main objective Maximize CPU utilization and throughput (keep CPU busy). Provide fast response time and fairness for interactive users.
Typical users Mostly job-oriented workloads (often non-interactive). Interactive, often multiuser environments (many users at terminals/sessions).
How CPU switches Usually switches when a job blocks for input/output (not necessarily timer-based). Switches using timer interrupts after each quantum (preemption) even if the job does not block.
Scheduling focus Keep CPU busy; reduce CPU idle time. Fair CPU sharing; keep system responsive; prevent one user from dominating.
Performance metric CPU utilization and throughput. Response time (and fairness) + acceptable overhead.
Resource usage / overhead Less frequent context switches → lower overhead (generally). More frequent context switches due to quanta → higher overhead, but better interactivity.
Relationship Base technique: multiple programs in memory, switch on wait. Built on multiprogramming + adds time slicing and strong fairness requirements.
Exam line (very important):

Multiprogramming aims to keep the CPU busy; time-sharing aims to keep the user happy (fast response + fairness).


6) How Time-Sharing Works (Step-by-step)

  1. Multiple users log in (each runs shell/editor/compiler etc.).
  2. Each user’s programs create processes; many processes become Ready.
  3. The scheduler selects one process and runs it for one time quantum.
  4. When the quantum expires (or the process blocks for input/output), the OS saves its context (PCB/registers) and switches to another.
  5. Over time, every user gets repeated CPU slices → interactive feel is maintained.

7) Choosing Time Quantum (Important Exam Point)

  • If quantum is too large: system behaves closer to batch; response becomes slow (users “wait”).
  • If quantum is too small: too many context switches; overhead increases; CPU time is wasted switching instead of working.
  • So the quantum must balance responsiveness and overhead.

8) Advantages and Limitations

Advantages

  • Fast response time for interactive work.
  • Fair sharing of CPU among users.
  • Better utilization when multiple processes are ready or when others are waiting for input/output.
  • Cost-effective multiuser environment (lab/server).

Limitations / Challenges

  • Context switch overhead (saving/restoring state frequently).
  • Needs a good scheduler and careful system tuning.
  • Security and protection become critical because many users share the same machine.
  • Can become slow if too many users run heavy CPU tasks simultaneously.

9) Diagram: CPU Time Slicing

Round-Robin style time slicing (example) Each process gets one quantum, then CPU switches to the next ready process. 0 Q 2Q 3Q 4Q 5Q P1 (User A) P2 (User B) P3 (User C) P4 (User D) P1 again Fast switching + repeated CPU slices = “interactive feel” for all users. If a process blocks for input/output, the scheduler skips it and runs another ready process.
Fig 4.1: CPU time slicing (quantum-based rotation) used in time-sharing systems.

10) Quick Self-Check Questions

  1. Define a time-sharing system and explain the role of time slicing.
  2. Define multiprogramming in one line and state its main objective.
  3. Compare time-sharing and multiprogramming in terms of objective and operation (any three points).
  4. Why do time-sharing systems usually require preemptive scheduling?
  5. What happens if the time quantum is too large? Too small?
  6. How does virtual memory help time-sharing?
  7. List two security/protection mechanisms needed in multiuser time-sharing systems.

Worked Example

Example: University Lab Server (100 Users)

Consider a university Linux server where many students log in simultaneously. Each student runs a shell, editor, and compiler.

User Experience (What students feel)

  • Everyone can type commands and see results quickly.
  • Editors remain responsive even when others compile.
  • No single student can “freeze” the system permanently.

OS Actions (What the time-sharing OS does)

  • Schedules CPU time fairly across all user processes (time slicing).
  • Isolates each user’s files and processes.
  • Applies limits (quotas) so one user cannot consume all CPU or memory.
  • Uses virtual memory so more users can remain active than RAM alone would allow.
Takeaway:

This is the classic environment where time-sharing systems are most valuable: many short interactive tasks, shared fairly, with strong isolation and security.

One-Page Summary

  • Definition: CPU switches rapidly among users/tasks so each user feels a dedicated system.
  • Core mechanism: time slicing (CPU time divided into quanta) + frequent context switching.
  • Main goal: fast interactive response time (not only throughput).
  • Scheduling: typically preemptive; quantum size balances responsiveness vs context-switch overhead.
  • Supports multiuser computing: isolation, protection, security, quotas, file permissions.
  • Virtual memory: helps support more active users/programs than physical memory alone.
  • Advantages: responsiveness, fairness, good resource sharing.
  • Challenges: overhead, scheduler complexity, security risks if not enforced properly.