IITP · Semester ISummaries · Quizzes · Assignments

Lecture summary

FCS 29 Aug

29 Aug 20262h 35m4 parts

Source: IITP-big-files\Sem-1\ECS5102-FCS\Lectures\2026-08-29 0000 FCS 29 Aug\summary\notes.md

Overview

This class focused on practical system observation in a Linux environment, establishing the operating system's role as the manager of hardware resources (CPU, memory, disk, network) on behalf of applications. Students used a Python web application (systemlab) to generate specific loads and observed the resulting hardware utilization via command-line tools (ps, top, htop, mpstat, /proc). The session connected high-level cloud concepts (compute, storage) to low-level OS modules (scheduler, virtual memory, file system) and demonstrated how the OS abstracts physical hardware for applications.

Learning outcomes

  • Use Linux commands (ps, top, htop, mpstat, curl, watch) to monitor CPU, memory, and disk utilization of a running process.
  • Interpret process information from /proc/[PID]/status and pmap.
  • Explain the roles of key OS modules: scheduler, virtual memory (including swap/paging), file system, and network stack.
  • Distinguish between CPU time and elapsed time for a process.
  • Describe the purpose of disk partitioning and LVM (Logical Volume Manager).
  • Articulate the performance trade-offs between RAM and disk storage.

Core concepts

Operating System as Resource Manager

The OS acts as a middleman between application software and physical hardware. It provides abstractions (processes, virtual memory, files) and manages resources via dedicated modules: the scheduler for CPU time, virtual memory for RAM and swap, the file system for disk I/O, and the network stack for communication. This management is observable through system monitoring tools.

Process Observation and States

A process is a program loaded into memory. Tools like ps and top reveal its state (e.g., sleeping, running), resource consumption (%CPU, %MEM), and relationships (PPID). Understanding the difference between CPU time (actual processor cycles used) and elapsed time (total wall-clock time) is crucial for performance analysis. The OS scheduler decides which process runs on which CPU core.

Virtual vs. Physical Resources

The OS creates virtual abstractions (virtual CPUs, virtual memory addresses) for processes, but these are bounded by physical resources. Virtual CPU and memory cannot exceed the actual, physical CPU and RAM capacity. The /proc filesystem provides a window into how the kernel manages these virtual resources for each process.

Storage Hierarchy and Performance

The system employs a storage hierarchy: fast, volatile RAM (temporary) and slower, persistent disk (permanent). Swap memory extends RAM onto disk via paging. Performance demonstrations (writing to /tmp vs. allocating memory) show that memory access is orders of magnitude faster than disk access. Cache (L1, L2, L3) sits between CPU and RAM for even faster access (covered in a previous session).

Disk Management: Partitioning and LVM

Disk partitioning splits a physical disk into logical sections (sda1, sda2) for purposes like isolating the /boot partition or controlling data placement. Logical Volume Manager (LVM) allows flexible management of space within a partition, enabling dynamic resizing of logical volumes, which is a common practice in server and cloud environments.

Formulas and maths

No formulas were presented in this session.

Worked examples

Disk Partitioning Layout

  • A 60 GB virtual disk (sda) was partitioned into:
    • sda1: 1 MB (type unknown).
    • sda2: 2 GB, type extended, mounted at /boot.
    • sda3: 58 GB, type LVM.
  • Within the 58 GB LVM partition (sda3), 29 GB was allocated to a volume named ubuntu--vg-ubuntu--lv. The remaining 29 GB was unallocated.
  • Total used space calculation: 1 MB + 2 GB + 29 GB = 31 GB. The 29 GB allocated to the LVM volume was noted as "allocated but not used."

Process Monitoring with ps and /proc

  • The systemlab.py script had PID 1740, using 0.5% of 4 GB RAM.
  • Its parent process was python3 (PID 1662), using 0.1% memory.
  • The parent of python3 was the Unix shell (PID 1660).
  • For PID 1750 (python3), /proc/1750/status showed:
    • Name: python3
    • State: sleeping
    • VmSize: 107 MB (current), with a peak of 1.2 GB (after a 1024 MB allocation command).
    • VmData: 19 MB.

Generating and Observing CPU Load

  • Command: curl localhost:8080/cpu?seconds=5
  • Observed in top: Process CPU utilization spiked to 41.3% (user time).
  • For a 20-second request: Sustained high CPU usage shown (e.g., 50% user, 49% idle).
  • mpstat showed one CPU core reaching 100% user + 0% idle during load, causing the OS scheduler to start utilizing a second core.

Generating and Observing Memory Load

  • Command: curl localhost:8080/memory?mb=512
  • Observed in htop: System memory usage increased from 356 MB to ~868 MB.
  • Command: curl localhost:8080/memory?mb=1024
  • Observed: Memory usage increased to 1.36 GB. Total system RAM was 3.27 GB (3024 MB).

Disk vs. Memory Performance Test

Using systemlab.py to write data: - Writing 512 MB to disk (/tmp): 0.14 seconds (14 ms). - Reading the same 512 MB from disk: 0.05 seconds (5 ms). - Writing 1024 MB to disk: 0.03 seconds to write, 0.1 seconds to read (noted as an unexpected result). - Attempting to write 2048 MB (2 GB) to /tmp failed due to insufficient space; the allocated temporary space was only 1.6 GB.

Questions asked in class

  • Priyanka: Will we need to write Python code for the exam?
    • Answer: No, not expected to write Python, but expected to understand the Linux commands used.
  • Anuj (regarding disk/partitioning): What is a loop device and the purpose of partitioning?
    • Answer: A loop device is created by the OS during installation to manage its own files. Partitioning (sda1, sda2, sda3) is for controlling data storage location, limiting application resource usage, and security (e.g., restricting access to /boot).
  • Shivam: Are there book recommendations or study materials for these system concepts?
    • Answer: The lecturer agreed to add Python learning resources when uploading the presentation.
  • Suraj: Can we replicate this lab on an AWS EC2 t2.micro instance (1 vCPU, 1 GB RAM)? Do commands differ for other Linux variants?
    • Answer: Yes, it can be replicated. Commands are largely the same across Linux distributions, with minor variations.
  • Deepak Roy: Can these exercises be done on a macOS terminal, or is Linux mandatory?
    • Answer: Yes, the Python program can run on macOS. The curl commands and outcomes will be the same. Learning Linux commands is beneficial but not strictly mandatory.
  • Varun: Does memory/disk management differ between x86 and x86_64 architectures?
    • Answer: Yes, hardware architecture dictates how memory and CPU are managed. OS distributions are compiled for specific architectures (x86, ARM, RISC).
  • Sorrow: Does a single program always use CPU core 0 first, then core 1? What about multiple programs?
    • Answer: For a single program, it typically uses core 0 first, then core 1 if needed. With multiple programs, the first might use core 0 and the second core 1. The OS scheduler manages core assignment.
  • Student: If one program uses core 1 and another uses core 2, where are the system (kernel) processes executed?
    • Answer: The OS scheduler decides. If it has assigned a kernel process to core 1, it runs on core 1. Kernel processes share the same physical cores as application processes.

Key takeaways

  • The OS provides key abstractions: processes, virtual memory, files, and sockets.
  • Use ps, top, htop, and mpstat to monitor real-time process activity and system resource utilization (CPU, memory).
  • The /proc filesystem is a virtual interface to kernel and process data; /proc/[PID]/status contains vital process details like state and memory usage (VmSize, VmData).
  • CPU time (actual execution) is distinct from elapsed time (total duration including waits).
  • Disk partitioning allows logical separation of a physical disk for organization, security, and resource control (e.g., a separate /boot partition).
  • LVM (Logical Volume Manager) enables flexible management of disk space within a partition, allowing volumes to be resized dynamically.
  • RAM access is significantly faster than disk access, defining a fundamental performance trade-off in system design.
  • Virtual resources (vCPU, virtual memory) are limited by physical resources (physical cores, RAM); the virtual cannot exceed the physical.
  • The OS scheduler assigns processes to CPU cores and can move them between cores; both application and kernel processes share these physical cores.
  • Tools like curl can generate specific loads (CPU, memory, disk) on a web server endpoint for observation and testing.
  • A process's parent process ID (PPID) shows the process that spawned it, forming a process tree.
  • The system daemon (systemd, PID 1) is the ancestor of all other processes and manages system services.

Exam-style questions

  1. Scenario: You run curl localhost:8080/cpu?seconds=10 and observe in top that the process uses 95% CPU. However, mpstat shows overall CPU idle time is 50%. Explain this apparent contradiction.

    • Answer Outline: The top percentage is per-core utilization. The process is likely pinned to a single core, using 95% of that core's capacity. mpstat shows an average across all cores. If the system has two cores, one core at 95% busy and the other mostly idle would average to ~47.5% busy, or 52.5% idle, matching the observation.
  2. A system has 8 GB of physical RAM. A process has a VmSize of 10 GB as reported in /proc/[PID]/status. Is this possible? Explain.

    • Answer Outline: Yes, this is possible. VmSize is the virtual address space allocated to the process, not the physical memory used. The OS uses the page table and virtual memory system to map this large virtual address space to the available 8 GB of physical RAM (and potentially swap space on disk). The process may not be actively using all 10 GB at once.
  3. Describe the purpose of having a separate /boot partition on a Linux system's hard disk.

    • Answer Outline: The /boot partition contains the bootloader and kernel images. Keeping it separate isolates critical boot files from the main OS filesystem. This can prevent the main filesystem from becoming full and corrupting boot files, simplify recovery, and allow for different filesystem types optimized for booting.

Glossary

  • Boot Partition (/boot) - A small disk partition containing bootloader and kernel files, accessed first during system startup.
  • CPU Time - The actual time a CPU spends executing instructions for a specific process.
  • Daemon - A background system process that runs continuously, often started at boot (e.g., systemd).
  • Elapsed Time - The total wall-clock time from the start to the end of a process.
  • LVM (Logical Volume Manager) - A system for managing logical volumes on a disk, allowing flexible allocation and resizing of storage space.
  • Partitioning - The act of dividing a physical disk into multiple logical sections, each appearing as a separate disk.
  • Process - An instance of a running program, with its own memory space and process ID (PID).
  • /proc filesystem - A virtual filesystem in Linux that provides an interface to kernel data structures and process information.
  • Resident Set Size (RSS) - The portion of a process's memory held in physical RAM (non-swapped).
  • Scheduler - The OS component responsible for deciding which process runs on which CPU core and for how long.
  • Swap Memory - Disk space used by the OS to extend physical RAM, with data moved via paging.
  • Virtual Memory Size (VSZ) - The total size of the virtual address space allocated to a process.
  • Zombie Process - A terminated process whose entry remains in the process table, often because its parent has not yet read its exit status.

Follow-ups

  • Detailed explanation of CPU cache (L1, L2, L3) and its role was referenced as covered in a previous session.
  • The mixed workload parameter for the systemlab.py server was not demonstrated due to a command error; the lecturer stated this would be covered in the next session.
  • Python code details for systemlab.py and prerequisite installation steps will be shared as a PDF via the course portal.
  • The lecturer acknowledged requests for concise study notes and sample papers, promising to provide them before exams.
  • Network abstraction concepts were mentioned as a topic to be covered if time permits in future sessions.