Inter-process communication using UNIX signals — a tiny client/server messaging system.
minitalk implements a small communication program between a server and a client using only the UNIX signals SIGUSR1 and SIGUSR2. The client encodes each character of a message into individual bits and sends them one by one to the server, which reconstructs the original string and prints it.
Each character (8 bits) is transmitted bit by bit, LSB first:
SIGUSR1represents a0bitSIGUSR2represents a1bit
The client sends each bit with kill(pid, signal) and shifts the character right after each send. The server accumulates bits in a static char, setting the appropriate bit position on each SIGUSR2 received. After 8 bits, it writes the reconstructed character and resets.
Client Server
│ │
│─── SIGUSR1 (bit 0) ──────────► │
│─── SIGUSR2 (bit 1) ──────────► │
│─── SIGUSR1 (bit 0) ──────────► │ ... (8 signals = 1 char)
│ │──► write(1, &letter, 1)
A usleep(100) between each signal gives the server time to process before the next arrives.
minitalk/
├── minitalk.h # Shared header — includes signal.h and bundled libft
├── client.c # Reads PID and message, sends bits signal by signal
├── server.c # Handles incoming signals, reconstructs and prints characters
└── libft/ # Bundled libft for ft_printf, ft_atoi, ft_strlen
makeProduces two binaries: server and client.
./serverOutput:
Server PID: 12345
Waiting for messages...
In a second terminal:
./client 12345 "Hello, 42!"The server prints:
Hello, 42!
- Wrong number of arguments → usage message to stderr and exit
- Invalid or unreachable PID → detected via
kill(pid, 0)before sending - Signal send failure → error message to stderr and exit
| Target | Description |
|---|---|
make / make all |
Build server and client |
make clean |
Remove object files |
make fclean |
Remove object files and binaries |
make re |
fclean + all |
- Uses
signal()for signal handling — sufficient for the mandatory part. - The server supports one client at a time; simultaneous clients would corrupt the static state.
- Bundled
libftused for output and argument parsing — no external dependencies. - Written in compliance with the 42 Norm.
42 Heilbronn — Core Curriculum