Linux system programming cheatsheet
A very dense reference of man pages excerpts I put together to remember what’s
what in the Linux (mostly POSIX) system programming.
Errors
Files
Low (syscall) level
Multiplexing
Wait for file descriptors to become ready for reading/writing.
Pipes
Standard I/O
Uses an additional user-space buffer (see setvbuf() below), so may be slower
than other methods, albeit more convenient in some cases.
Thread Safety
Extended I/O (syscalls)
See also:
Extended attributes (support depends on FS)
Manage arbitrary string key/value pairs for files stored with the file metadata.
Directories
Devices
- /dev/null
- /dev/zero
- /dev/full (ENOSPC on write)
- /dev/urandom
- /dev/random (more random, but can block for a long time!)
Filesystem events
Obtain events by reading from fd. Example:
Processes
See also EXIT_SUCCESS and EXIT_FAILURE
Users/groups
Manage effective user/group ID of the current(calling) process.
Scheduling
PThreads
NB: compile with ‘gcc -pthread’
Mutexes
Memory management
Memory allocation
Memory manipulation
Signals
Signal sets
Extended signals
Time
clockid_t:
- CLOCK_REALTIME - wall clock, can be changed by root (resolution: ticks)
- CLOCK_MONOTONIC - time since, for ex., last boot; can’t be adjusted (ticks)
- CLOCK_MONOTONIC_RAW - same as above(?); Linux-specific (resolution: ticks)
- CLOCK_PROCESS_CPUTIME_ID - hi-res (nanosec) CPU clock
- CLOCK_THREAD_CPUTIME_ID - per-thread hi-res (nanosec) CPU clock
Adjust time
Sleeping
Alarms