A 42 school project: two programs, server and client, that exchange a text message using nothing but UNIX signals (SIGUSR1 / SIGUSR2) — no sockets, pipes, shared memory, or files.
- The client sends the message to the server one bit at a time:
SIGUSR1for a1bit,SIGUSR2for a0bit, least-significant bit first, 8 signals per byte. - The server's signal handler accumulates 8 incoming signals into a byte and
write()s it to stdout as soon as it has a full byte — the message appears on the server's terminal as it's received. - Since the protocol just moves raw bytes (not "ASCII characters"), multi-byte UTF-8 text — accented letters, emoji, non-Latin scripts — comes through correctly too: each byte of the UTF-8 encoding is simply sent as its own group of 8 signals.
Mandatory (server / client) |
Bonus (server_bonus / client_bonus) |
|
|---|---|---|
| Byte transmission | SIGUSR1/SIGUSR2, 8 signals/byte, LSB first |
Same |
| End of message | Client appends a trailing \n, sent like any other byte |
Client appends \n and a \0 byte; the server specifically recognizes \0 as "message finished" |
| Acknowledgment | None — client sends and exits without confirmation | Once the server sees the terminating \0, it sends SIGUSR1 back to the client to confirm full receipt |
| PID handshake | Not needed (no ack) | Before the message, the client sends its own PID as 32 signals (LSB first) so the server knows where to send the acknowledgment |
| Delay between signals | usleep(125) |
usleep(150) |
| PID / argument validation | Numeric PID required; existence checked via kill(pid, 0) |
Same |
Neither version does per-character flow control — both rely on a fixed usleep delay to avoid overwhelming the signal queue. The bonus only adds a single end-to-end acknowledgment, not per-byte confirmation.
make # mandatory: builds "server" and "client"
make bonus # bonus: builds "server_bonus" and "client_bonus"make clean # remove object files
make fclean # remove object files and all four binaries
make re # fclean + allTerminal 1 — start the server:
./server
Server PID: 12345Terminal 2 — send a message:
./client 12345 "Hello, world!"The message shows up on the server's terminal as it's received.
Bonus — same idea, with a delivery confirmation:
./server_bonus./client_bonus 12345 "Hello, world!"
Message is complated(that's the exact string the program prints on acknowledgment, typo and all)
client/client_bonusrefuse a non-numeric PID, reject a PID that doesn't correspond to a running process (kill(pid, 0)check), and printConnection lost.if the server process disappears mid-transmission.server/server_bonusrefuse to start if given any command-line arguments — they only accept./server/./server_bonuswith nothing after it.
.
├── Makefile
├── server.c # Mandatory server
├── client.c # Mandatory client
├── server_bonus.c # Bonus server — adds the end-of-message acknowledgment
└── client_bonus.c # Bonus client — sends its PID first, waits for the ack
MIT — see LICENSE.