C · Unix signals · 42 Common Core
minitalk
Two programs that talk to each other using only two Unix signals, one bit at a time.
The problem
The problem
Send a text message from a client to a server when the only channel is SIGUSR1 and SIGUSR2, and print it correctly, including non-English characters.
What I built
- A server that prints its PID and rebuilds each character from incoming bits.
- A client that sends every byte bit by bit with kill().
- Bonus: the server acknowledges each message with a signal back, and full UTF-8 characters are supported.
Technical decisions
- sigaction with SA_SIGINFO, so the server knows which client sent each signal and resets if a new one starts.
- The first byte of a character tells how many bytes follow (UTF-8), so multi-byte characters print whole.
What makes it hard
- Signals can be lost if they arrive too fast, so the sender has to pace itself.
- Only a few functions are safe inside a signal handler.
What I can do because of it
- Understand inter-process communication and how signals really work.
- Encode and decode data at the bit level, including UTF-8.