Starting the Server
After building the project, start the server with:Server Startup Output
When the server starts successfully, you’ll see:The PID (Process ID) will be different each time you start the server. In this example, the PID is
12345.How the Server Works
Server prints its PID
On startup, the server displays its process ID:You need this PID to send messages from the client.
Server registers signal handlers
The server sets up handlers for two UNIX signals:
SIGUSR1represents a0bitSIGUSR2represents a1bit
Server waits for signals
The server enters an infinite loop, pausing until it receives signals:The
pause() function suspends execution until a signal is received.Getting the Server PID
The server displays its PID in the startup message. You can also find it using system tools:Example Session
- Terminal 1: Server
- Terminal 2: Client
Server Behavior
Infinite Loop
The server runs continuously until explicitly stopped. It uses
pause() to wait efficiently without consuming CPU.Signal-Driven
All communication is handled through UNIX signals (SIGUSR1 and SIGUSR2), making it a pure signal-based IPC mechanism.
Character-by-Character
Messages are received and printed one character at a time as each set of 8 bits arrives.
No Buffering
Characters are printed immediately using
ft_printf("%c", c) without waiting for a complete message.Stopping the Server
To stop the server, use keyboard interrupt:SIGINT signal that terminates the process.
The server doesn’t handle SIGINT specially, so it will terminate immediately without cleanup. Any partially received message (less than 8 bits) will be lost.
Alternative: Kill Command
You can also stop the server using thekill command:
Server Limitations
No message boundaries
No message boundaries
The server prints characters as they arrive without indicating where one message ends and another begins. If you send multiple messages, they’ll appear concatenated.
No client feedback
No client feedback
The server doesn’t send acknowledgment signals back to the client, so the client can’t verify successful receipt.
Single-threaded
Single-threaded
The server processes one signal at a time. If multiple clients send signals simultaneously, they may interfere with each other.
No null terminator handling
No null terminator handling
The server prints each character immediately. Null bytes in messages will not be visible but will reset the character buffer.
Troubleshooting
Server doesn't start
Server doesn't start
Ensure the executable has been built:And that it has execute permissions:
Can't find the PID
Can't find the PID
The PID is printed in the first line of output:If you missed it, check with
pgrep server or restart the server.No output when receiving messages
No output when receiving messages
Verify:
- The server is still running (not killed)
- The client is using the correct PID
- The client successfully sent the message without errors