IITP · Semester ISummaries · Quizzes · Assignments

Lecture summary

FCS 04 Oct

04 Oct 20263h 07m5 parts

Source: IITP-big-files\Sem-1\ECS5102-FCS\Lectures\2026-10-04 0000 FCS 04 Oct\summary\notes.md

Overview

This class introduced the operating system's role as the manager between applications and physical hardware. It covered the complete chain from hardware to kernel to processes, establishing core OS pillars: the kernel, system calls, processes, scheduling, and context switching. The session distinguished between a passive program and an active process, detailed the process lifecycle and identification via PID, and explained the scheduler's role. It also explored the privilege boundary between user mode and kernel mode, the anatomy of a process, and categories of system calls. The discussion concluded with the kernel's role in managing specialized hardware like GPUs.

Learning outcomes

  • Explain why an operating system is necessary to run user applications.
  • Distinguish between a program, a process, and a thread.
  • Describe the flow of a resource request from an application to the kernel via a system call and to the hardware.
  • Identify the key components the OS uses to manage a process (PID, PC, registers, stack, heap).
  • Explain the difference between user mode and kernel mode and how system calls cross this privilege boundary.
  • List major categories of system calls (e.g., process control, file management).
  • Classify a process as Ready or Blocked/Waiting from its situation.
  • Name the system call a parent uses to wait for a child, and the calls that create, replace and end a process.
  • Explain the trade-off between the many-to-one and one-to-one threading models.

Core concepts

Operating System as Manager

The OS is the mandatory manager between applications (e.g., Word, PowerPoint) and the physical computer hardware (CPU, RAM, disk). No application can access hardware directly; all requests must be mediated by the OS kernel. This management ensures controlled, secure, and efficient resource sharing among multiple running programs.

Kernel

The kernel is the core, privileged part of the operating system that controls access to all computer resources (CPU, memory, devices). It is not the entire OS but its central manager. The kernel itself runs on the hardware and receives requests from applications, which it fulfills by managing hardware availability and initiating actions via system calls.

System Call

A system call is the controlled interface for a user-mode application to request services from the kernel. It is the mandatory entry point for performing privileged operations like opening files or creating processes. Crossing from user mode to kernel mode via a system call changes the CPU's privilege level. System calls are categorized (e.g., process control, file management, communication).

Process vs. Program

A program is a passive set of stored instructions (e.g., PowerPoint.exe on disk). A process is an active, executing instance of a program, with its own dedicated memory space and state. The OS creates a process via a system call (e.g., fork) and assigns it a unique Process ID (PID). Resource allocation (memory, CPU time) is granted to the process, not directly to the application.

Process Lifecycle System Calls

The process-control calls divide the work: fork() duplicates the current process to create a child, exec() replaces the process image with a new program, exit() ends the process, and wait() (or waitpid()) makes the parent wait for its child to finish. wait() also reaps the child's termination status and prevents a zombie.

Process States: Ready vs. Blocked/Waiting

A Ready process is able to run but is not currently on a CPU; it sits in the run queue waiting for the scheduler. A Blocked/Waiting process cannot run until an event occurs, such as the completion of an I/O operation (e.g., waiting for disk data); it sits in the wait queue. The run queue holds Ready processes, the wait queue holds Blocked ones.

Thread

A thread is a lightweight unit of execution within a process. Threads share the memory and resources (code, data, heap) of their parent process, making them faster and cheaper to create and terminate than independent processes. Context switching between threads is faster because they belong to the same process already in memory.

Threading Models

In the many-to-one model, many user threads map to a single kernel thread. Because the kernel sees only one schedulable entity, a blocking system call in one user thread blocks all of them. This is why the one-to-one model (each user thread maps to one kernel thread) is the default on Linux/Windows.

User Mode vs. Kernel Mode

This is a privilege boundary enforced by the CPU and OS. User mode is where applications and most utilities run, restricted from direct hardware access. Kernel mode is where the kernel executes, with full privilege to access hardware and system resources. A system call triggers the transition from user to kernel mode.

Process Anatomy

The OS maintains a distributed set of information to manage a single running process. Key components include: Process ID (PID), Program Counter (PC), CPU registers, stack (for function calls), heap (for dynamic memory), code/text, data, file descriptors, scheduling information, credentials, and parent-child links. This information is not stored in one contiguous block but across kernel data structures.

Scheduler

The scheduler is a component of the kernel (not a process itself) that monitors resource utilization and decides which ready process gets access to the CPU and for how long. It maps processes to available CPU cores. Scheduling priority typically follows: system processes > application processes, with further prioritization within system calls (e.g., write operations may get priority over reads).

Context Switching

The act of saving the execution state (PC, registers, etc.) of a currently running process and restoring the state of another process so it can run. This enables multitasking. Switching between processes has high overhead due to swapping the memory context, while switching between threads within the same process is faster.

Kernel Bypass

In specific high-performance scenarios (e.g., networking), applications can communicate directly with hardware like a Network Interface Card (NIC) to achieve lower latency and higher throughput, using techniques like RDMA (Remote Direct Memory Access). The kernel still allocates the resource initially, but control remains with the application. This is an exception, not a general rule for application-kernel interaction.

Formulas and maths

(No formulas were covered in this session.)

Worked examples

  1. Concurrent Programs: The lecturer's laptop was running at least 4-5 programs in parallel: PowerPoint, a browser, Microsoft Teams, VMware, and other training-related applications.
  2. System Call Flow for Opening a File: Opening resume.doc in Microsoft Word involves the application (in RAM) requesting the kernel via the fopen system call. The kernel coordinates reading the file from the hard disk and displaying its content.
  3. Print Request Process Lifecycle: A print request gets a parent process ID (e.g., 5273). It creates a child process (e.g., 5279) to handle moving data from memory to printer memory. The parent (5273) waits. The child (5279) gets resources, transfers data, exits, and releases its resources. The parent then gets resources to confirm completion to the user, then also exits.
  4. Process ID Examples: Different instances/tabs of the same application have different PIDs. Chrome tab 1 (Gmail) might have PID 101, Chrome tab 2 (AI tool) might have PID 102, a terminal PID 103.
  5. File Descriptor Numbers: Standard descriptors are 0 for stdin (keyboard/mouse), 1 for stdout (monitor/printer), 2 for stderr. User-opened files start at descriptor 3.
  6. Resource Allocation Policy: If a system has 64 MB free RAM and a policy reserves 32 MB for emergency system calls, a process may wait even with "free" memory available.
  7. CPU Affinity: An application can be configured so that all its processes run only on the first three cores of the CPU.
  8. Word Document Paging: The entire document is not loaded into RAM at once. Scrolling triggers system calls that create short-lived processes to fetch more data from disk to RAM via paging, after which the processes exit. The main winword.exe process runs continuously.
  9. GPU Capability: A CPU might create 22 processes for an application, but a GPU with a higher capability might support 222 processes in parallel. The kernel needs to know this number to submit work appropriately.
  10. Classifying Two Processes: One process is runnable and waiting for a CPU, another is waiting for disk data. The first is Ready (able to run, not currently on a CPU, sitting in the run queue). The second is Blocked/Waiting (cannot run until the I/O event completes, sitting in the wait queue).
  11. Parent Waiting for a Child: A parent must wait for its child to finish. The call is wait() (or waitpid()). It also reaps the child's termination status and prevents a zombie. Related calls: fork() duplicates, exec() replaces the image, exit() ends the process.
  12. Many-to-One Threading: In the many-to-one model, many user threads map to one kernel thread. Because the kernel sees only one schedulable entity, a blocking system call in one user thread blocks all of them — which is why the one-to-one model (each user thread = one kernel thread) is the default on Linux/Windows.

Questions asked in class

  1. Sorrow: Could not connect individual concepts (process, kernel, process state) in the flowchart. Asked for a description of the flow when opening an application like Microsoft Word.
    • Answer: Opening Word requires resources (RAM, processor). The OS kernel receives the request, runs on the hardware, and manages hardware availability. It acts via a system call (e.g., fopen), which initiates a process to coordinate reading the file from disk and displaying it.
  2. Varun: Asked about thread vs. process, priority processes, and whether the scheduler is a process.
    • Answer: Clarified differences (isolation, creation time, context switching). The scheduler is a kernel component, not a process. Discussed priority: system processes > application processes.
  3. Sanjeev: How does the OS decide which process gets the CPU when 100 processes are running?
    • Answer: Mapping is between CPU cores and processes. The scheduler allocates free cores to ready processes. Priority: system > application. Within applications, priority can be based on operation type (e.g., write > read).
  4. Mohit: Are fork, execute functions in a C program part of the OS/kernel?
    • Answer: They are C library functions. When executed, they trigger a system call to the kernel. The kernel creates the process via the system call. Resource allocation is to the process.
  5. Brajesh: How does kernel bypass work for devices like network cards?
    • Answer: Kernel bypass (e.g., for NICs) allows apps to communicate directly with hardware for lower latency (using RDMA). The kernel still allocates the resource, but control remains with the app.
  6. Multiple Students: Are the system calls in the user-kernel diagram and the earlier chain diagram the same? Is the interaction bi-directional when more resources are needed? Does editing a Word doc require more processes? How does a process ID persist during context switches? What if required RAM exceeds available RAM? Can we see if a process is in user or kernel mode?
    • Answer: Yes, same system call interface. Request flow is one-way (app → kernel → process), but the kernel can communicate back. Word uses a main process and short-lived processes for paging. PID persists while process is not in exit state. If RAM is exceeded, paging occurs between RAM and disk. User/kernel mode visibility will be shown in a lab.
  7. Anuj: Asked about GPU kernel alignment and optimizing distributed training via kernel programming.
    • Answer: GPU kernel alignment involves optimizing memory access, execution structure, and data layout for GPU parallel throughput. Optimizing distributed training with GPU kernels is a broad topic requiring a different session.
  8. Unnamed Student: Asked about loading a model and where optimizations ("optimization state") and data structure updates happen when data is loaded between GPU data structures.
    • Answer: This is an important but complex question that requires a different session altogether. The instructor asked the student to hold the question for later.

Key takeaways

  • An Operating System is mandatory for running any user application; it acts as the manager between software and hardware.
  • The Kernel is the core, privileged manager of the OS that controls all resource access; applications cannot contact hardware directly.
  • A System Call is the only controlled interface for an application to request kernel services, crossing the privilege boundary from user mode to kernel mode.
  • A Process is an active instance of a program, created by a system call, with its own PID, memory space, and state. A Program is the passive code on disk.
  • A Thread is a lightweight execution unit within a process, sharing its memory, enabling faster creation and context switching than separate processes.
  • The Scheduler is a kernel component that allocates CPU cores to ready processes based on priority (system processes > application processes).
  • Context Switching saves and restores process state (PC, registers) to enable multitasking; it is more expensive between processes than between threads.
  • The OS manages a process using distributed information: PID, Program Counter, registers, stack, heap, file descriptors, and scheduling data.
  • User Mode and Kernel Mode are CPU privilege levels; system calls trigger the transition from restricted user mode to privileged kernel mode.
  • Kernel Bypass (e.g., RDMA) is a specialized exception allowing direct app-to-hardware communication for performance, but the kernel still oversees allocation.
  • Process IDs (PIDs) are unique and persist as long as the process is not in the exit state, even across context switches.
  • When system RAM is insufficient, Paging swaps data between RAM and disk to manage memory, loading only portions of data at a time.
  • A Ready process can run but is not on a CPU (run queue); a Blocked/Waiting process cannot run until an event such as I/O completion (wait queue).
  • fork() duplicates, exec() replaces the image, exit() ends the process, and wait()/waitpid() makes the parent wait for the child and reaps its status, preventing a zombie.
  • In the many-to-one threading model a blocking system call in one user thread blocks all of them, since the kernel sees only one schedulable entity; the one-to-one model is the default on Linux/Windows.

Exam-style questions

  1. Describe the complete sequence of events, naming all OS components involved, when a user double-clicks a Word document icon to open it.
    • Answer Outline: User action triggers the shell/application. The Word application (in user mode) issues a system call (e.g., open) to the kernel. The kernel (in kernel mode) validates the request, allocates resources (RAM), and creates a new process with a unique PID to handle the file operation. The process loads the document data from disk into the allocated memory via further system calls. The kernel's scheduler may allocate CPU time to this process. The loaded content is returned to the Word application for display.
  2. Compare and contrast processes and threads. List two advantages of using threads within a single application.
    • Answer Outline: A process is an independent execution instance with its own memory space; a thread is a lightweight unit within a process that shares the process's memory. Advantages of threads: 1) Faster creation/termination and lower overhead because they share existing resources. 2) Faster context switching between threads as there is no need to swap the entire memory address space.
  3. A system is running many applications and becomes sluggish. Using OS concepts, explain two possible reasons related to process management and resource allocation.
    • Answer Outline: 1) Excessive Context Switching: High number of active processes causing the scheduler to frequently save/restore states, consuming CPU cycles. 2) Memory Pressure/Thrashing: Required RAM exceeds physical RAM, leading to excessive paging between RAM and disk, which is very slow and stalls processes waiting for data to be swapped in.
  4. What is the difference between a C library function like fork() and the actual system call? Explain the role of the kernel in this scenario.
    • Answer Outline: The fork() in a C program is a library function that provides a convenient interface for the programmer. When called, it ultimately triggers/invokes the actual fork system call. The system call is the request that crosses the privilege boundary into the kernel. The kernel then performs the privileged operation of creating a new child process, allocating resources, and returning the new PID.
  5. One process is runnable and waiting for a CPU; another is waiting for disk data. Classify each and name the queue it sits in.
    • Answer Outline: The first is Ready — able to run but not currently on a CPU; it sits in the run queue. The second is Blocked/Waiting — it cannot run until the I/O event (disk data arrival) completes; it sits in the wait queue.
  6. A parent process must wait for its child to finish. Which system call does it use, and how does it relate to fork(), exec() and exit()?
    • Answer Outline: It uses wait() (or waitpid()). fork() duplicates the process to create the child, exec() replaces the process image, exit() ends the process, and wait() blocks the parent until the child terminates, reaps the child's termination status, and prevents a zombie.
  7. Explain the many-to-one threading model and its main drawback. Why is the one-to-one model the default on Linux/Windows?
    • Answer Outline: In many-to-one, many user threads map to a single kernel thread. Because the kernel sees only one schedulable entity, a blocking system call in one user thread blocks all of them. The one-to-one model (each user thread = one kernel thread) avoids this and is therefore the default on Linux/Windows.

Glossary

  • Blocked/Waiting - A process state where the process cannot run until an event (e.g., I/O completion) occurs; such processes sit in the wait queue.
  • Context Switching - The act of saving the state of a running process and restoring the state of another so it can run, enabling multitasking.
  • exec() - A system call that replaces the current process image with a new program.
  • exit() - A system call that ends a process and releases its resources.
  • fork() - A system call that duplicates the current process to create a child process.
  • Kernel - The core, privileged part of the operating system that manages all hardware resources and system services.
  • Kernel Bypass - A specialized technique allowing applications direct access to hardware (e.g., NIC) for high performance, with kernel oversight.
  • Many-to-One Threading Model - A model mapping many user threads to one kernel thread; a blocking system call in one thread blocks all of them.
  • One-to-One Threading Model - A model mapping each user thread to one kernel thread; the default on Linux/Windows.
  • Process - An active, executing instance of a program, with its own memory space and state, identified by a PID.
  • Process ID (PID) - A unique numerical identifier assigned by the OS to each process.
  • Program Counter (PC) - A CPU register holding the memory address of the next instruction to execute for a process.
  • Ready - A process state where the process is able to run but is not currently on a CPU; such processes sit in the run queue.
  • Run Queue - The queue holding Ready processes awaiting CPU time from the scheduler.
  • Scheduler - The kernel component responsible for deciding which ready process gets access to the CPU and for how long.
  • System Call - The controlled interface through which a user-mode process requests a service from the operating system kernel.
  • Thread - A lightweight unit of execution within a process that shares the process's memory and resources.
  • User Mode / Kernel Mode - CPU privilege levels; user mode restricts direct hardware access, while kernel mode allows full system control.
  • Wait Queue - The queue holding Blocked/Waiting processes until their awaited event occurs.
  • wait() / waitpid() - System calls that make a parent wait for its child to finish, reap the child's termination status, and prevent a zombie.
  • Zombie - A terminated child process whose termination status has not yet been reaped by its parent via wait().

Follow-ups

  • Detailed discussion on "OS process" or "priority process" (promised to Varun).
  • The exact PID number boundary between system and application processes (lecturer was unsure).
  • Types of system calls and how they determine priority within system processes.
  • How a shell script can attain privilege mode (cross user/kernel boundary) with kernel assistance.
  • Lab demonstration: Show a Python program executing and visually trace its interaction with system calls, kernel, and hardware components, including determining if a process is in user or kernel mode.
  • The detailed mechanism of optimizations ("optimization state") and data structure updates when models are loaded and executed on a GPU (to be covered in a future session).
  • The lecturer will now post assignments directly to the system, not via shared files.