5102 - Foundations of Comp Sys
← 5102 - Foundations of Comp Sys
session: "5102-foundations-of-comp-sys/2026-10-10 0000 FCS 10 Oct"
title: "FCS 10 Oct"
date: "2026-10-10 00:00"
duration: "1h 46m"
language: "en"
model: "deepseek-ai/DeepSeek-V3.2"
parts: 3
transcript_chars: 64652
generated: "2026-11-23T15:46:04+05:30"
This class focused on the practical interface between user-space applications and the operating system kernel via system calls. It began by demonstrating common terminal commands (cat, uname, ps) to illustrate the chain from user input to kernel action. The core activity involved writing, compiling, and tracing simple C programs to observe process creation (fork, getpid) and file I/O (open, read, write) system calls using strace. The session concluded with a discussion on system log management, process visibility, and a preview of upcoming topics like virtual memory and inter-process communication, situating these practical observations within the broader course theme of the hardware/software contract.
strace.fork, getpid, and file I/O system calls.Definition: User space is the memory region where all application programs (e.g., shell, browsers, user-written C programs) run. Kernel space is the protected memory region where the core operating system (the kernel) executes.
Why it matters: This separation is a fundamental security and stability mechanism. Applications in user space cannot directly access hardware or privileged kernel data; they must request services via system calls.
Connection: This boundary is the central theme of the class, explored through tracing system calls that cross from user space into the kernel.
Definition: A controlled entry point into the kernel through which a user-space application requests a service, such as reading a file, creating a process, or getting the current time.
Why it matters: System calls are the only way for applications to access hardware resources managed by the kernel, enforcing the hardware/software contract.
Connection: The entire class session is built around observing system calls (open, read, write, fork, getpid) using the strace utility.
Definition: A process is a running instance of a program. The kernel assigns each process a unique Process ID (PID) to identify and manage it.
Why it matters: Understanding PIDs is essential for tracking process relationships, resource ownership, and for using tools like ps and strace.
Connection: The getpid() system call was demonstrated, and the fork() system call was shown to create a new child process with a different PID.
Definition: A unique integer handle returned by the kernel when a process opens a file or other I/O resource (like a network socket). It is used in subsequent read, write, and close calls to refer to that resource.
Why it matters: File descriptors abstract the details of the underlying resource (file on disk, pipe, device) and are a core mechanism for I/O within a process.
Connection: In the file_demo.c example, the open system call returned file descriptor 3, which was then used for read and close.
Definition: fork() is a system call that creates a new child process, which is an almost identical copy of the parent process. The parent's PID becomes the child's Parent Process ID (PPID).
Why it matters: This is the primary mechanism for process creation in Unix-like systems. It establishes a relationship where the parent typically waits for the child to collect its exit status.
Connection: A fork demo program showed the parent and child PIDs, and strace revealed the underlying clone system call and the parent's wait4 call.
(Not covered in this session)
1. Shell PID: Ran echo $$ in the terminal, which displayed the PID of the current shell (e.g., 2006).
2. Process List: Ran ps, which showed active processes including sudo, su, bash, and ps itself.
3. Changing User Context: Exited root shell and re-entered with sudo su -. The new shell had a different PID (2930), demonstrating that a new process was created.
identity.c)1. Program Purpose: Printed process ID and system information using getpid() and uname().
2. Compilation: gcc -Wall -Wextra identity.c -o identity
3. Execution Output:
3256LinuxIIT partner 2026 autumn7.0.0.34 genericx86_644. Targeted Tracing with strace:
strace -e uname ./identity: Traced only the uname system call, showing it was called by process 3283.strace -e getpid,write ./identity: Traced getpid and write calls. Showed getpid returning PID 3298 and write being called from printf.file_demo.c)1. Program Flow:
open("demo.txt", O_CREAT | O_TRUNC | O_RDWR, 0644). Permission 0644 means: owner can read/write (6), group can read (4), others can read (4).lseek(fd, 0, SEEK_SET) to move the file offset back to the start.2. Output: The program printed the file descriptor (3) and "bytes returned is 25" (the length of "transaction id transaction 1001").
3. Tracing: strace ./file_demo showed the sequence of openat, write, lseek, read, and close system calls, with file descriptor 3 used throughout.
fork_demo.c)1. Program Flow:
fork() (e.g., 3764).fork(), the parent printed its PID (3764) and the child's PID (3765), then waited.3765) and its parent's PID (3764), then exited.2. Tracing with strace -f: The -f flag follows child processes.
strace -f -e clone,wait4,exit_group ./fork_demo3791 called clone to create child 3792.3791 then called wait4 for child 3792.3792 called exit_group(0) to terminate.3791 finally called exit_group(0).1. Goal: To create a child process that terminates before its parent reads its exit status, leaving it in a "zombie" state.
2. Attempt: Lecturer ran a program where the parent sleep()s for 30 seconds after forking. The child was designed to exit immediately.
3. Check Command: Used ps -o pid,ppid,state,cmd to look for processes in the zombie (Z) state.
4. Outcome: The demonstration failed as the ps output did not show the expected zombie. The lecturer noted the program needed fixing and deferred the demo to the next session.
strace is a basic utility; there are other tools (some with GUI) that provide more detailed information.strace utility is a powerful tool for observing the system calls made by a program, revealing its interaction with the kernel.open() and used for subsequent I/O operations like read() and write() within a process.fork() system call creates a new child process, which is a copy of the parent. The child gets a new PID, and the parent's PID becomes the child's PPID.wait() (or a variant like wait4()) to collect the child's exit status and prevent it from becoming a zombie.ps is governed by user privileges: administrators can see all processes, while normal users typically see only their own.cat, ps, and echo themselves rely on a series of system calls (open, read, write, fork, exec) to perform their tasks.1. You run strace -e openat,read,write cat /etc/hostname. Describe the sequence of system calls you would expect to see and explain the purpose of each in the context of displaying the file's content.
openat to open the file /etc/hostname, returning a file descriptor. Multiple read calls to read the file content into a buffer. One or more write calls to write that content to file descriptor 1 (standard output). Finally, a close call (if traced) to close the file descriptor.2. A C program calls fork(). Immediately after the fork, how can the child process distinguish itself from the parent process in code? What system calls could each use to print its own PID and its parent's PID?
fork() returns 0 to the child and the child's PID to the parent. The child can use getpid() for its PID and getppid() for the parent's PID. The parent can use getpid() for its own PID and already has the child's PID as the return value from fork().3. Explain what a zombie process is. What condition creates it, and what system call (or action) by the parent process removes it from the system?
wait() (or similar). The parent must call wait() (or waitpid, wait4) to "reap" the child, at which point the zombie entry is removed from the process table.1. mmap (memory mapping) and brk (relating to virtual memory mapping to physical memory).
2. Inter-process communication (IPC).
3. Scheduling and context switch (if not covered tomorrow).
One line per segment, [hh:mm:ss] timestamp first.
loading…