Lecture 00: Prerequisites and Overview
Prerequisite Guide: Undergraduate Operating Systems Concepts and Laboratory
This document outlines the foundational knowledge and practical skills required for the undergraduate Operating Systems course.
Operating Systems is often the first course where students transition from writing high-level application code to interacting directly with system resources. The laboratory assignments will be conducted in a Linux environment and will require you to write programs in C that manage processes, memory, and file systems.
To succeed in this course, students must possess a strong grasp of basic procedural programming, data structures, and command-line navigation before the semester begins.
1. Conceptual Prerequisites
You must be comfortable with low-level memory concepts and foundational computer architecture.
1.1 The C Programming Language
The course labs rely heavily on C. Unlike Java or Python, C does not have garbage collection or built-in bounds checking.
- Pointers and Addresses: Dereferencing pointers, passing by reference versus passing by value, and pointer arithmetic.
- Memory Management: Dynamic memory allocation using
malloc,calloc,realloc, and explicitly freeing memory withfree. Understanding the difference between the Stack and the Heap. - Strings and Arrays: Understanding that strings in C are simply null-terminated character arrays (
' '). - Structs: Defining custom data types and accessing their members (using
.and->operators).
To-Do / Self-Assessment: Write a C program that dynamically allocates an array of
nintegers (wherenis provided by the user). Populate the array with random numbers, write a function to sort them in place, print the result, and correctly free the allocated memory.
1.2 Data Structures
Operating systems heavily utilize foundational data structures to manage queues of processes and memory blocks.
- Required Proficiency: You must be able to implement Singly and Doubly Linked Lists, Queues, and Stacks from scratch in C.
- Algorithmic Complexity: Basic understanding of Big-O notation (e.g., knowing why an $O(1)$ lookup time is preferable to $O(n)$ for a system scheduler).
To-Do / Self-Assessment: Implement a doubly linked list in C. Write functions to
insert_head,remove_tail, andprint_list. Ensure your code handles edge cases, such as removing an item from an empty list.
1.3 Computer Organization Basics
You should understand the basic operation of a computer at the hardware level.
- The Von Neumann Model: The fetch-decode-execute cycle of a CPU.
- Memory Layout: How a compiled program is loaded into memory (Text segment, Data segment, Heap, and Stack).
- Number Systems: Proficiency in converting between binary, hex, and decimal representations.
2. Laboratory Tooling & Environment
The laboratory component requires proficiency in a POSIX-compliant environment (Linux). Graphical User Interfaces (GUIs) will not be used for assignments.
2.1 Linux Command Line Interface (CLI) Basics
You must be able to navigate the file system and manipulate files using the terminal.
- Navigation:
pwd,ls(e.g.,ls -la),cd. - File Operations:
touch,mkdir,cp,mv,rm(understand the danger ofrm -rf). - Viewing Files:
cat,less,head,tail. - Getting Help: The
mancommand (e.g.,man 3 printfto view the C library manual forprintf).
2.2 Compilation and Build Tools
- GCC (GNU Compiler Collection): Compiling source code to executables.
- Example:
gcc -Wall -Wextra -g myprogram.c -o myprogram
- Example:
- Makefiles: Understanding how to use
maketo automate the compilation of multiple.cand.hfiles. You should be able to read a basicMakefileand run it.
2.3 Debugging and Profiling
Segmentation faults are the most common error in this course. You must know how to trace them.
- GDB (GNU Debugger): Starting a program, setting a breakpoint (
break main), stepping through code (step,next), and printing variable values (print var). - Valgrind: Essential for detecting memory leaks and invalid memory accesses.
- Example:
valgrind --leak-check=full ./myprogram
- Example:
To-Do / Self-Assessment: Introduce a deliberate memory leak in your linked list code from Section 1.2 (e.g., remove a node without calling
free). Compile the code with the-gflag and run it through Valgrind. Observe the output report and fix the leak.
2.4 Note for Windows Users
The lab environment is exclusively Linux. If you are using a Windows machine for personal study, you should familiarize yourself with the following tools to interface with Linux environments:
- Windows Subsystem for Linux (WSL 2): Highly recommended for running a native Ubuntu environment locally on Windows.
- SSH Clients: Tools like PuTTY or the native Windows OpenSSH client to connect to university lab servers remotely. (Note: Visual Studio IDE and MSVC compiler are Windows-specific and will not compile POSIX-compliant OS lab code correctly. Rely on WSL/GCC).
3. Recommended Reading List
The following texts bridge the gap between basic programming and systems-level understanding.
- Operating Systems: Three Easy Pieces (OSTEP) by Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau.
- Note: This will likely be the primary textbook for the course. It is highly readable and available for free online. Focus on the early chapters covering Virtualization (Processes and Memory).
- Computer Systems: A Programmer’s Perspective (CS:APP) by Randal E. Bryant and David R. O’Hallaron.
- Note: Excellent for understanding the transition from C code to machine execution. Chapters on system-level I/O and virtual memory are highly relevant.
- The C Programming Language (2nd Edition) by Brian W. Kernighan and Dennis M. Ritchie.
- Note: The definitive guide for C syntax and standard library functions. Keep it as a reference for lab assignments.