CodeRigor

FREE COURSE / REAL PRACTICE

Unix & Linux systems (C++)

Work with native Unix/Linux interfaces from C++: descriptors, files, processes, memory mapping, signals, epoll and sockets.

Free lessons & exercises9 authored lessons3 units

What you’ll work toward

Manage operating-system resources, handle partial work and errors, and build deterministic native exercises.

Read an explanation, inspect the diagrams and work through the available checks, debugging exercises and builds. Feedback and prerequisite links guide the next step.

Before you start

This course builds on these skills:

Individual lessons can add prerequisites. The course map shows your actual readiness.

A look inside the first lesson

Descriptors & open file descriptions

C++
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <fcntl.h>
#include <unistd.h>

int main() {
    char name[]="/tmp/unix-check-XXXXXX"; int fd=::mkstemp(name); assert(fd>=0); ::unlink(name);
    assert(::write(fd,"abcdef",6)==6); assert(::lseek(fd,0,SEEK_SET)==0);
    int other=::dup(fd); assert(other>=0); char a=0,b=0;
    assert(::read(fd,&a,1)==1); assert(::read(other,&b,1)==1);
    std::printf("%c%c %ld\n",a,b,long(::lseek(fd,0,SEEK_CUR))); ::close(other);::close(fd);
}

Your course outline

Follow the lessons in curriculum order. Open a unit to preview the ideas you’ll work with.

UNIT 013 lessons Unix/Linux: files, descriptors & filesystem
  1. LESSON 01.01

    Descriptors & open file descriptions

    Own Linux descriptors in C++: move-only RAII, atomic close-on-exec duplication, shared offsets and status flags, independent descriptor flags and errno-safe cleanup.

    Open lesson
  2. LESSON 01.02

    Syscalls, short I/O & positioned files

    Handle errno, EINTR, short reads/writes and EOF; use pread/pwrite without disturbing shared offsets, reject Linux append-mode traps, and test error paths deterministically.

    Open lesson
  3. LESSON 01.03

    Directories, inodes & relative path operations

    Separate names, inodes and open handles; walk directory descriptors with openat, reject symlinks, understand unlink/rename, permissions and the limits of userspace path policies.

    Open lesson
UNIT 023 lessons Unix/Linux: processes, memory & signals
  1. LESSON 02.01

    Processes: fork, exec, pipes & wait

    Launch a program without a shell, arrange inherited descriptors, distinguish exec failure from exit status, drain a pipe before waiting and reap every child.

    Open lesson
  2. LESSON 02.02

    Virtual memory & mapped file windows

    Map an unaligned file slice with page-aligned mmap, separate ownership from spans, transfer mappings safely, and understand MAP_PRIVATE, page faults and SIGBUS after truncation.

    Open lesson
  3. LESSON 02.03

    Signals & descriptor-based notifications

    Distinguish signal delivery from queued work; consume blocked signals with signalfd and aggregate wakeups with eventfd without allocating or logging in a signal handler.

    Open lesson
UNIT 033 lessons Unix/Linux: event-driven networking & IPC
  1. LESSON 03.01

    Nonblocking I/O & epoll readiness

    Build a level-triggered readiness layer with 64-bit tokens, bounded nonblocking drains, buffered-data-plus-hangup handling, and explicit EAGAIN versus EOF semantics.

    Open lesson
  2. LESSON 03.02

    TCP sockets, connection state & half-close

    Bind a loopback listener to an ephemeral port, complete a nonblocking connect with SO_ERROR, accept safely, and distinguish TCP byte streams, EOF and half-close.

    Open lesson
  3. LESSON 03.03

    Unix sockets & passing open descriptors

    Transfer a kernel open-file reference with SCM_RIGHTS, parse ancillary messages, set close-on-exec at receipt, and close every installed descriptor on malformed/truncated messages.

    Open lesson