Workshop: Linux System Programming Fundamentals - Day 1/2

Day 1/2

This two-day workshop provides a solid understanding of the operating system architecture and low-level interfaces (principally, system calls and library functions) that are required to build system-level applications on Linux (and UNIX) systems. By completion of the workshop, participants will have a good understanding of the construction of many common Linux and UNIX programs (e.g., the shell, ls(1), and cp(1))

- Full course description
- Course Book

1. Course Introduction

2. Fundamental Concepts
- System calls and library functions
- Error handling
- System data types
- Notes on code examples

3. File I/O and Files
- File I/O overview
- open(), read(), write(), and close()
- The file offset and lseek()
- Relationship between file descriptors and open files
- Duplicating file descriptors
- File status flags (and fcntl())
- Retrieving file information: stat()

4. Directories and Links (*)
- Directories and (hard) links
- Symbolic links
- Hard links: system calls and library functions
- Symbolic links: system calls and library functions
- Current working directory
- Operating relative to a directory (openat() etc.)

5. Processes
- Process IDs
- Process memory layout
- Command-line arguments
- The environment list
- Process credentials
- The /proc filesystem

6. Signals
- Overview of signals
- Signal dispositions
- Signal handlers
- Useful signal-related functions
- Signal sets, the signal mask, and pending signals
- Designing signal handlers
- Async-signal-safe functions
- Interrupted system calls

7. Process Lifecycle
- Introduction
- Creating a new process: fork()
- Process termination
- Monitoring child processes
- Orphans and zombies
- The SIGCHLD signal
- Executing programs: execve()

8. System Call Tracing with strace (*)
- Getting started
- Tracing child processes
- Filtering strace output
- System call tampering
- Further strace options

9. Pipes and FIFOs
- Overview
- Creating and using pipes
- Connecting filters with pipes (*)

10. Alternative I/O Models
- Overview
- Nonblocking I/O
- I/O multiplexing: poll()
- Problems with poll() and select()
- The epoll API
- epoll events
- epoll: edge-triggered notification
- Event-loop programming

Topics marked with an (*) are optional, and will be covered
as time and interest permit.

The following people are likely to find the workshop of particular benefit:
* Programmers developing system-level applications for Linux systems, or programmers porting such applications from other operating systems (e.g., Windows) to Linux.
* Embedded programmers developing applications for Linux, or porting embedded applications from systems such as VxWorks or QNX to Linux.
* DevOps engineers and sytem administrators who want to gain a greater insight into the operation of Linux applications.

The workshop consists of a mixture of detailed presentations coupled with many coding exercises that allow participants to apply the knowledge learned in the presentations.

* You should have a good reading knowledge of C or C++. For the practical sessions, templates will be provided to relieve you of the need to type in tedious boilerplate code. The templates are in C, but if you wish, it is also possible to complete the exercises in another suitable language such as D, Rust, or of course C++.
* You should have a basic familiarity with the Linux/UNIX command line to do tasks such as listing directories, editing files, and compiling programs.
* No previous system programming experience is assumed.

Computer Setup
You'll need a laptop with Linux installed--either as a native install or inside a virtual machine (VM). In the latter case, you should ensure that the VM has working Internet access. The system should have a C compiler (e.g., gcc) and "make" installed. (It's likely that both of these are provided as part of the default install, if you are setting up a new system.)