/engineering-skills:systems-programmingfrom engineering-skills
Provides rules for code that calls the operating system directly, covering file descriptors, durable writes, processes, signals, threads, interprocess communication, and the toolchain.
Ships in engineering-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
ROLE: You are a systems engineer. You write code that calls the operating system.
CORE FUNCTION: You receive a task that touches files, processes, or memory. You produce code that stays correct when the system is busy, when a call stops early, and when the machine loses power.
Code at this level fails differently from application code. It fails only under load. It fails only on one machine. It fails only after a power loss. The defect is in the code from the first day. The test suite does not find it.
This skill exists to make those defects visible before the code runs.
Four skills use the word "system". They answer different questions. Read this table before you choose one.
| Skill | Question it answers | Level |
|---|---|---|
system-design | What must we build? | Architecture |
data-systems-design | Does the design stay correct across machines? | Distributed data |
systems-programming (this skill) | Does the code stay correct against the kernel? | One machine |
security-engineering | Can an attacker break it? | Threat |
Use this skill when the code calls the kernel. Use system-design when the code does not
exist yet.
Use this skill for these tasks:
EINTR, EAGAIN, EPIPE, ENOSPC, EMFILE, ETXTBSY.Do not use this skill for these tasks:
system-design.A high-level language does not remove these rules. Python, Go, Java, Rust, and Node.js call the same system calls. The runtime hides some faults. The runtime does not hide all of them. Section 6 lists the faults that each runtime still exposes.
Learn these five rules. They cause most defects in low-level code. Check every rule on every review.
A system call returns an error for reasons that your code did not cause. The disk becomes full. The process reaches its file descriptor limit. Another user removes the directory.
Check the return value of every call. This includes close. A failed close can report a
write error that the kernel found after your last write call returned.
if (close(fd) < 0)
/* the data may be lost. Report this error. */
Never ignore the result of close on a file that you wrote.
read and write can transfer fewer bytes than you request.A short count is not an error. It is normal behavior for pipes, sockets, terminals, and large transfers. A signal can also stop a transfer after some bytes move.
Call read and write in a loop until the count reaches the total that you need.
ssize_t writen(int fd, const void *buf, size_t n); /* loop until n bytes move */
ssize_t readn(int fd, void *buf, size_t n); /* loop until n bytes or end of file */
Stevens and Rago give these two functions in Section 14.7 for this reason.
A single write call that you do not check is the most frequent defect in file code.
EINTR.A signal that arrives during a slow system call makes that call return −1. errno becomes
EINTR. The call did no work, or it did partial work.
Handle EINTR in one of two ways:
SA_RESTART in sigaction. Then the kernel repeats some calls for you.SA_RESTART does not cover every call. It does not cover select, poll, or a socket call
that has a timeout. Write the retry loop for those calls.
The kernel can stop your process between any two calls. Another process runs in that gap.
Stevens and Rago state the rule directly:
"Any operation that requires more than one function call cannot be atomic, as there is always the possibility that the kernel might temporarily suspend the process between the two function calls."
This rule creates a whole class of defects:
| Two calls | The defect | The atomic form |
|---|---|---|
lseek to end, then write | Two processes overwrite each other's records | Open the file with O_APPEND |
lseek, then read | The offset changes between the calls | pread |
stat, then open | The path points to a different file at open time | open, then fstat |
access, then open | An attacker replaces the path. This is a privilege defect. | open, then check with fstat |
open to test, then creat | Another process creates the file and writes to it. That data is lost. | open with O_CREAT and O_EXCL |
close, then fcntl | A signal handler changes the file descriptor in the gap | dup2 |
Find every pair of calls that forms one logical operation. Replace the pair with the atomic call.
fsync.A write call that returns success did not put the data on the disk. The kernel copied the
data into a buffer. The kernel writes that buffer later. Stevens and Rago call this a
delayed write.
A power loss between the write call and the disk write loses the data.
| Function | What it does | When it returns |
|---|---|---|
sync | Puts every changed buffer in the write queue | At once. It does not wait for the disk. |
fsync(fd) | Writes the data and the attributes of one file | After the disk write finishes |
fdatasync(fd) | Writes the data of one file. It skips some attributes. | After the disk write finishes |
Call fsync when the data must survive a crash. Section 3 gives the full recipe.
fsync on the file is not enough. A new file name lives in its directory. You must also
call fsync on the directory that holds the file.
These recipes solve the file tasks that appear most often. Each one is correct against concurrent processes and against a power loss. Use them as written.
These recipes apply to document ingestion, index building, cache files, and any pipeline that reads many files and writes derived files.
Never write over a file in place. A crash in the middle leaves a file that holds half of the old content and half of the new content. Readers cannot detect that state.
Use these six steps:
mkstemp.fsync on the temporary file.close on the temporary file. Check the result.rename to move the temporary file onto the target name.fsync on the directory that holds the target file.rename replaces the target in one atomic step. A reader sees the old file or the new file.
A reader never sees a mixed state.
Two rules control step 1:
rename fails
across file systems. A different directory is often a different file system.mkstemp creates the file with
mode 0600.Step 6 is the step that engineers omit most often. Without step 6, a power loss can leave a directory that does not hold the new name.
Call open with O_CREAT and O_EXCL together. The kernel tests for the file and creates
the file in one atomic step.
fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0644);
if (fd < 0 && errno == EEXIST)
/* another process owns this name */
This is the correct way to make a lock file. Do not test with stat first. Rule 4 explains
why.
Open the file with O_APPEND. The kernel moves the offset to the end of the file before
every write call, as one atomic step.
Two limits apply:
write call. Two calls can interleave with another process.Do not call lseek before write. That pair loses records. Rule 4 gives the reason.
fstat on the file descriptor, not stat on the path. The path can change.read returns 0.Do not trust the size from fstat as the exact byte count. The file can grow between the
fstat call and the read call. Use the size to reserve memory. Use the loop to find the
end.
Set a maximum size before you read. A file on disk can be larger than your memory. A named pipe has no end until the writer closes it.
Use opendir and readdir. Use closedir at the end.
Four rules apply:
. and ... Without this test, the walk does not stop.lstat, not stat. lstat reports the link itself.open. Use openat and fstatat with the
file descriptor of the parent directory. This method removes the race in Rule 4. It also
removes any limit on path length.PATH_MAX. Some file systems permit a longer path. Some systems do not
define the constant.readdir returns the entries in no defined order. Sort the entries when the order matters
to your output.
Choose the method by the size of the file and the access pattern.
| Method | Use it when | Cost |
|---|---|---|
read into a buffer of 64 KB or more | You read the file from start to end, one time | Copies the data one time |
mmap | You read the file many times, or you jump between offsets | The kernel maps pages. It skips the copy. |
pread | Many threads read one file at different offsets | No shared offset. No lock. |
Rules for mmap:
mmap region ends at the size of the file at map time. Another process that truncates
the file makes your program receive SIGBUS.mmap does not help for a file that you read one time from start to end. The page faults
cost more than the copy.For the buffer size in the read method: measure. Stevens and Rago show that the time
falls until the buffer reaches the block size of the file system. A larger buffer gives no
further gain.
Use fcntl with F_SETLK or F_SETLKW. This is POSIX record locking.
POSIX record locks have two behaviors that surprise engineers. Both cause defects.
close on any file descriptor for that file releases every lock that the
process holds on the file. A library that opens and closes the same file releases your
lock.Use flock when you need a lock that belongs to the open file description, and when your
platform supports it. Use a lock file from Recipe 2 when you need a lock on a whole file and
no byte ranges.
A lock on a network file system is not reliable. Do not depend on it.
Donovan gives a general design procedure. It applies to an assembler, a loader, a macro processor, and a compiler. It applies equally to a parser, an indexer, a log processor, or any program that changes one form of data into another form.
Follow these five steps in order:
| Step | Action | Output |
|---|---|---|
| 1 | Write the statement of the problem | What goes in. What comes out. What the program must not do. |
| 2 | Choose the data structures | The tables that the program needs, and what each table holds |
| 3 | Fix the format of the data bases | The exact layout of every table and every file |
| 4 | Write the algorithm | The passes, and the work in each pass |
| 5 | Look for modularity | The parts that you can separate and test alone |
Step 3 is the step that engineers skip. Donovan separates the data structure from its format for a reason. The structure says what the program holds. The format says how the bytes sit in memory or on disk. A format that you did not write down becomes a defect at the boundary between two passes.
The number of passes comes from the data, not from taste. An assembler needs two passes because a symbol can appear before its definition. Pass 1 builds the symbol table. Pass 2 generates the code. When your program must resolve a forward reference, it needs a second pass or a patch list.
Use the same question for any tool that you write. Ask this question: does any output depend on input that the program has not read yet? When the answer is yes, plan two passes.
An engineer who does not know these steps cannot read a link error or a load error.
Donovan separates three time periods. Keep them apart when you debug.
| Period | Name | What happens |
|---|---|---|
| Translation | Assembly time or compile time | The source becomes an object file |
| Loading | Load time | The loader puts the program in memory and fixes the addresses |
| Running | Execution time | The processor runs the instructions |
Donovan states that a relocating loader performs four functions:
Every loader type does these four functions. The types differ only in when each function happens. A direct-linking loader does all four at load time. A dynamic linker delays linking and relocation until the program calls the symbol.
This model explains the errors that you see:
| Error | Which function failed |
|---|---|
| "undefined symbol" at build time | Linking. No object file defines the name. |
| "undefined symbol" at run time | Linking, delayed to run time by the dynamic linker |
| "cannot open shared object file" | Allocation. The loader cannot find the library file. |
"text file busy" (ETXTBSY) | Loading. You wrote to a file that a running program uses. |
| Wrong version of a function runs | Linking. Two libraries define the same name. |
For the memory layout of a running process, read references/08-toolchain-and-machine-model.md.
A runtime hides some of the five rules. It does not hide all of them. Check this table before you decide that a rule does not apply.
| Rule | C | Go | Rust | Python | Java | Node.js |
|---|---|---|---|---|---|---|
| Check every return value | You | Runtime raises an error value | Runtime returns Result | Runtime raises | Runtime raises | Runtime raises |
Short read and write | You | You, unless you call io.ReadFull | You, unless you call read_exact | Hidden for files. You for sockets and pipes. | Hidden by streams. You for SocketChannel. | You. A stream can send partial data. |
EINTR | You | Hidden since Go 1.14 | Mostly hidden | Hidden since Python 3.5 | Hidden | Hidden |
| Two calls are not atomic | You | You | You | You | You | You |
fsync | You | You | You | You | You | You |
Rule 4 and Rule 5 are never hidden. No runtime makes two calls atomic. No runtime calls
fsync for you when you close a file. A durable write in any language needs Recipe 1.
Two more items that no runtime hides:
references/05-signals.md.fork in a process that has threads copies only the calling thread. Read
references/06-threads-and-concurrency.md.Run this scan on any change that touches a file, a process, or a signal. Report only the items that apply.
Files and descriptors
close?read or a short write?fsync on the file and on the directory?FD_CLOEXEC on descriptors that a child process must not receive?open on a path that it tested with stat or access earlier?Processes
wait or waitpid for every child?fork for all three cases: −1, 0, and positive?Signals
errno?volatile sig_atomic_t?sigaction instead of signal?EPIPE or block SIGPIPE?Threads
fork while other threads run?Memory and resources
The full list, with the consequence and the fix for each item, is in
references/failure-catalog.md.
| Type of change | Output |
|---|---|
| A read of one small file, through a library | Rule 1 only |
| A write to a file that a person can lose | Recipe 1. Say that you applied it. |
| A directory walk or a document ingest | Recipe 5 and Recipe 6. Run the file section of the scan. |
| A new process, a daemon, or a signal handler | The full scan for that section |
| Shared memory, a lock, or a thread | The full scan, plus a written statement of the ordering rules |
| A change to a build, a link step, or a load path | Section 5 |
This skill uses one word for one meaning. Use these words in your output.
| Word | Meaning in this skill |
|---|---|
| system call | A function that moves control into the kernel |
| file descriptor | The small integer that a process uses to name an open file |
| open file description | The kernel record that holds the offset and the status flags |
| atomic | The kernel performs every step, or the kernel performs no step |
| durable | The data stays on the disk after a power loss |
| reentrant | A second call is safe while the first call has not finished |
| async-signal-safe | A signal handler can call this function |
| short count | read or write moved fewer bytes than the caller requested |
| choose | To select one option. The word select always means the system call. |
| record | To write information into a document |
| Reference | Content | Read it when |
|---|---|---|
references/01-file-descriptors-and-io.md | File descriptors, open, read, write, lseek, sharing, atomic calls, dup, fcntl, nonblocking I/O, select and poll, readv, mmap | Any file or socket I/O |
references/02-files-and-directories.md | stat, file types, permissions, umask, hard links, symbolic links, rename, directory reading, openat, durable update, path safety | Any file management task |
references/03-standard-io-and-buffering.md | Streams, the three buffer modes, fflush, mixed stream and descriptor I/O, temporary files, when not to use a stream | You use FILE, printf, or a language stream |
references/04-processes-and-execution.md | Memory layout, environment, fork, exec, wait, exit status, races, process groups, sessions, daemon rules | You start or manage a process |
references/05-signals.md | Signal concepts, sigaction, reentrancy, the async-signal-safe list, EINTR, signal masks, the self-pipe method, job control signals | You write or review a signal handler |
references/06-threads-and-concurrency.md | Thread creation and exit, mutexes, condition variables, reader-writer locks, deadlock order, thread-local data, threads with fork, threads with signals | Any thread work |
references/07-ipc-and-sockets.md | Pipes, FIFOs, SIGPIPE, shared memory, semaphores, sockets, Unix domain sockets, passing a file descriptor, message framing | Two processes exchange data |
references/08-toolchain-and-machine-model.md | The machine model, assembly and load and run time, the four loader functions, static and dynamic linking, symbol resolution, the process address space | You debug a build, link, or load error |
references/failure-catalog.md | 55 named failure modes with a signature, a consequence, and a fix. It also has an index by symptom. | Any review. Any defect that appears only sometimes. |
Related skills. Use security-engineering when the code holds a privilege, or when it
handles a path from a user. Many defects in this skill are also privilege defects. Use
data-systems-design when the data moves between machines.
Sources. The rules and the numbers come from these books:
references/01-file-descriptors-and-io.md (opens in a new tab)references/02-files-and-directories.md (opens in a new tab)references/03-standard-io-and-buffering.md (opens in a new tab)references/04-processes-and-execution.md (opens in a new tab)references/05-signals.md (opens in a new tab)references/06-threads-and-concurrency.md (opens in a new tab)references/07-ipc-and-sockets.md (opens in a new tab)references/08-toolchain-and-machine-model.md (opens in a new tab)references/failure-catalog.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
os-calls, file-descriptors, process-management, signals, threads, ipc
Other plugins' skills for the same job
npx claudepluginhub cool-coder174/engineering-skills --plugin engineering-skills18 skills in this plugin
/capacity-engineeringFinds the resource that reaches its limit first. Proves it with a load test that resembles real traffic. Plans for the load that was measured. Use this skill for capacity planning, a load test, a stress test, or a bottleneck hunt. Use it for a question about headroom, saturation, or throughput. Use it for utilization, queue depth, thread pool size, or connection pool contention. Use it for cache hit rate, precomputed content, garbage collector tuning, or session timeout. Use it for N+1 queries, table scans, or a launch traffic forecast. Use it for load balancing policy, subsetting, and server count. The content comes from Release It! (Nygard) and Site Reliability Engineering (Beyer and others)./code-reviewMulti-mode code review engine with six commands (/review-diff, /review-uncommitted, /review, /review-inscope, /review-data, /review-security) for branch diffs, uncommitted changes, full repository audits, scoped task reviews, data/distributed-systems hazard audits, and adversarial security review. Produces severity-ranked findings with concrete fixes, hazard and vulnerability scans, scope checks, and merge-readiness verdicts. Use when reviewing code, PRs, diffs, uncommitted changes, auditing a repo, or assessing security risk./data-systems-designDesign-decision engine for data-intensive and distributed systems, grounded in Designing Data-Intensive Applications (Kleppmann). Use when a task touches storage, schemas, migrations, replication, sharding, caching, transactions, queues, event streams, retries, background jobs, multi-service writes, or any non-functional requirement (latency, availability, throughput, durability, consistency). Provides decision tables, a named-hazard catalog, and deep-dive references per chapter./detail-planningExpands one phase of plan.md into a deterministic, file-referenced implementation spec in executor.md — including failure-mode analysis, idempotency and retry contracts, schema compatibility matrix, isolation levels, observability, and rollback. Use when the user says detail, detail planning, breakdown, or expand phase./engineering-consultantRead-only engineering consultant with two duties. It compares frameworks, libraries, databases, platforms, and tools, and states a recommendation the reader can act on and can challenge. It explains a technical concept to a person new to it. Use it to choose a framework, compare two tools, evaluate a vendor, onboard a new engineer, read unfamiliar code, or ask for a recommendation. Use it for "should we use X or Y", "what is the difference between X and Y", "explain X", and "how does X work". It reads the repository, the documentation, and the web. It never writes a file. It routes build work to the specialist skills./engineer-workflowUnified engineering pipeline orchestrating Planning, Design, Security, Detail Planning, Implementation, Verification, and Review as one navigable workflow with persistent state in plan.md/executor.md and history tracking. Supports greenfield and brownfield projects. Use when the user wants an end-to-end workflow rather than a single phase.