typestar

Systems programming

14 steps in 6 sets of C.

C talking to the operating system. Environment and exit codes, time, processes and signals, files and directories, and finally sockets.

This is POSIX territory, which is to say it is what Unix looks like from the inside. Fourteen steps, and it explains a lot of behavior you have previously just worked around.

Start this tour

Program environment

Time

Processes & signals

  • forkfork returns twice: zero in the child, the child's pid in the parent.
  • Replacing the process with execexec never returns on success, because the process becomes the new program.
  • Pipes between processesA pipe is a pair of descriptors: the child writes, the parent reads.
  • SignalsA handler runs on interrupt, and it may only touch async-signal-safe things.

Files & directories

Sockets

  • A TCP clientsocket, connect, write, read, close — the whole client in five calls.

Encore

  • tcp_echo.cA single-threaded echo server: bind, listen, accept, echo, repeat.

The other C tours