
Call POSIX APIs Safely with the nix Crate
Use the nix crate to call POSIX functions like pipe, fork, waitpid and kill from Rust with typed arguments, Result errors and no raw unsafe libc calls.
Processes, threads, files, memory mapping, signals, IPC and sockets through POSIX and Win32: the core every other kind of system is built on.

Use the nix crate to call POSIX functions like pipe, fork, waitpid and kill from Rust with typed arguments, Result errors and no raw unsafe libc calls.

Install the Rust toolchain, bindgen and libclang, check them with make rustavailable, enable CONFIG_RUST in a Linux 6.18 tree and build the Rust samples.

What changes when you write Rust for the Linux 6.18 kernel: no std, fallible allocation, errno Results, panics that act like BUG, and no main function.

Match on io::ErrorKind to handle NotFound, PermissionDenied and read-only filesystems from Rust std::fs, and use File::try_lock to detect a locked file.

What Rust for Linux is, what the 6.18 kernel actually contains, why the project adopted it as an experiment, and how abstractions keep unsafe code in one place.

Rust's standard library does not talk to the kernel directly on Linux. It calls libc, which issues the syscall. See the layers from File::open down to openat.

Read lines of any length in C with getline, reuse one growing buffer, strip the newline, spot read errors and handle files without a final newline.

Report failures from a C tool the Unix way: perror, strerror and the err and warn family, with errno saved correctly and messages sent to stderr.

Write a cat-style filter in C that reads the files named on the command line, uses standard input when there are none, and treats a lone hyphen as stdin.

What exit status 0, 1, 2, 126, 127 and 128 plus a signal number mean on Linux, how a shell reads them, and which codes your own command-line tool should return.

Use getopt_long in C to accept --name and --name=value options, fill in the option table, handle flags and abbreviations, and keep short options working.

Learn how getopt walks argv in C, what optind, optarg and opterr mean, how a colon marks an option value, and how to handle errors and bundled flags.
We send one email when a new post is published. No spam.