Assignment 01: System Calls and OS Structures
Self-Assessment
Instructions: Answer the following questions concisely. For code analysis and architectural design questions, ensure you justify your reasoning based on operating system principles.
Part A: Core Concepts and Workflows
- System Call Definition: In your own words, define what a system call is and explain why user programs cannot bypass this interface to interact directly with hardware.
- The Execution Flow: Outline the exact lifecycle of a system call, starting from the user application and ending at the kernel service routine. List the intermediate steps in order.
- The Kernel Boundary: Why do system calls require a dedicated CPU instruction (such as a trap to kernel mode) rather than functioning like standard C function calls?
Definition: A system call is a controlled interface through which user programs request services from the operating system kernel, such as file access, process creation, or device control. User programs cannot bypass this interface because system calls enforce privilege separation, ensuring secure interaction between user and kernel space.
Execution Flow: The correct sequence is:
User Application.
Function Call to Library Function (e.g., libc).
Syscall Instruction triggering the System Call Interface.
Kernel Executes the request.
Kernel Service Routine.
- Kernel Boundary: System calls require a switch to kernel mode because user programs must invoke a lower-level syscall instruction that triggers a CPU trap. This ensures privileged operations (like I/O and memory management) remain strictly isolated from unprivileged user space.
Part B: System Call Categorization
Match the following specific system calls to their correct functional category. Provide a brief explanation of what the system call does.
System Calls:
fork()ioctl()pipe()gettimeofday()open()
Categories:
- A. Information Maintenance
- B. Process Control
- C. Communication
- D. File Management
- E. Device Management
fork(): Process Control. It is used to create processes and is security-critical as it affects process isolation.ioctl(): Device Management. It is security-sensitive because it interacts directly with hardware.pipe(): Communication. It is performance-sensitive and is used in Inter-Process Communication (IPC).gettimeofday(): Information Maintenance. It is a lightweight call used for system bookkeeping.open(): File Management. It is performance-sensitive due to frequent I/O operations.
Part C: Architectural Design and Trade-offs
- Monolithic vs. Microkernel: Compare and contrast the Monolithic kernel architecture with the Microkernel architecture. In your comparison, address the primary trade-off between execution speed and system reliability.
- Architectural Application: Assume you are the lead architect for the following computing systems. Which classical OS architecture would you choose for each, and why?
- A safety-critical operating system used in an autonomous drone.
- A general-purpose desktop operating system.
- Monolithic vs. Microkernel:
Monolithic: All OS services (file system, memory, device drivers) run in kernel space as a single large binary. It is fast due to direct function calls, but suffers from poor modularity, meaning bugs can crash the entire system.
Microkernel: Only essential services (IPC, scheduling) run in kernel space, while others run in user space. This provides high modularity and better fault isolation, but introduces a performance overhead due to Inter-Process Communication (IPC).
- Architectural Application:
Autonomous Drone: A microkernel architecture is favored here, as microkernels are preferred in embedded and safety-critical systems for their reliability and modularity.
Desktop OS: A hybrid kernel (or monolithic kernel) is appropriate, as modern desktop OSes like macOS and Windows use hybrid kernels to balance performance and reliability. Linux itself uses a hybrid monolithic model to remain fast but extensible.
Part D: Theoretical Code Analysis
Review the following conceptual C code snippet and answer the related questions.
#include <unistd.h>
#include <stdio.h>
int main() {
pid_t pid = fork();
if (pid == 0) {
printf("Child Process\n");
} else {
printf("Parent Process\n");
}
return 0;
}
- Process Duplication: When the
fork()system call is executed, what lower-level syscall does the Linux operating system use internally to implement it? - Memory State: Immediately after the
fork()execution succeeds, describe the state of the child process regarding its Process ID (PID) and its memory space relative to the parent.
Process Duplication: Internally, Linux uses the
clone()syscall to implementfork().Memory State: The child process is assigned a new PID. Furthermore, the child receives a complete copy of the parent’s memory space.
Part E: Advanced Synthesis & Application (Exam Preparation)
Instructions: These exercises require you to synthesize multiple concepts from the lecture. Provide detailed, well-reasoned answers.
Exercise 1: The strace Investigation (System Boundary Analysis)
In the laboratory, you are tasked with executing the command strace ls on a standard Linux terminal to observe how processes interact with the kernel in real time.
Task: Based on your theoretical knowledge of system call categories, predict at least three distinct categories of system calls that
stracewill output during the execution of a simplelscommand.Challenge: Provide one specific example of a system call for each of your predicted categories and explain its necessity in the context of listing directory contents.
- Grading Criteria: The student must correctly identify categories and match them to logical syscalls.
- Expected Answer:
Process Control: The shell must use
fork()andexecvp()to spawn thelsprocess.File Management: The process must use
open()to access the directory, andread()orwrite()to process the contents.Information Maintenance: The process may query metadata using bookkeeping calls.
Exercise 2: Architectural Case Study Defense You have been hired as the lead systems architect for a medical technology company developing the operating system for a next-generation, life-support ventilator.
- Task: You must choose between a Monolithic architecture and a Microkernel architecture. State your choice.
- Challenge: Defend your choice by explicitly comparing the trade-offs in performance, modularity, and fault isolation between the two architectures. What is the catastrophic risk of choosing the incorrect architecture in this specific scenario?
- Grading Criteria: The student must select Microkernel and justify it using fault isolation.
- Expected Answer: A Microkernel is the correct choice, as they are favored in embedded and safety-critical systems for their reliability and modularity. In a Monolithic kernel, a bug in a single module (like a device driver) can crash the entire system. For a life-support ventilator, this lack of fault isolation is a catastrophic risk. While a microkernel introduces performance overhead due to IPC message passing, the superior fault isolation guarantees that a non-essential service failure will not halt the core life-support scheduling.
Exercise 3: Inter-Process Communication (IPC) Code Tracing Analyze the following theoretical C snippet designed to send data from a parent process to a child process using a pipe.
#include <unistd.h>
int main() {
int fd[2];
pipe(fd);
if (fork() == 0) {
close(fd[1]);
dup2(fd[0], STDIN_FILENO);
execlp("wc", "wc", "-w", NULL);
} else {
close(fd[0]);
write(fd[1], "hello world\n", 12);
close(fd[1]);
}
return 0;
}
Task: Identify the exact system calls used for process control and the system calls used for communication.
Challenge: Explain the necessity of the
close(fd[1])call inside the child process block and theclose(fd[0])call inside the parent process block. What happens at the kernel level if these are omitted?
Grading Criteria: Correct categorization of syscalls and understanding of pipe file descriptors.
Expected Answer:
Process Control:
fork()andexeclp().Communication:
pipe()andwrite().Challenge Explanation: The
pipe()system call creates a unidirectional data channel.fd[0]is the read end, andfd[1]is the write end. The child must close the write end (fd[1]) because it is only reading from the parent. The parent must close the read end (fd[0]) because it is only writing. If these are not closed, the kernel will not send an End-Of-File (EOF) signal to the reader when the writer finishes, causing thewcprogram to hang indefinitely waiting for more input.
Exercise 4: The Kernel Module Challenge (Exploratory) Modern operating systems allow for dynamic extensibility.
Task: If you were tasked with writing a minimal kernel module that logs every system call made by user applications, at what specific layer of the system call flow diagram would your module need to intercept the data?
Challenge: Why is it strictly impossible to implement this logging tool purely in user space as a standard library function (like a modified
libc)?
- Grading Criteria: Understanding of the system call interface and privilege separation.
- Expected Answer: The logging module must intercept data at the System Call Interface or within the Kernel Service Routine. It cannot be implemented purely in user space (e.g., by modifying
libc) because user applications can easily bypasslibcand invoke the syscall instruction directly. To guarantee all system calls are logged, the interception must happen after the CPU switches to kernel mode, enforcing strict privilege separation.