Executables
server
The server executable starts a process that receives messages via UNIX signals.Usage
Behavior
- Displays its PID on startup for clients to use
- Registers signal handlers for SIGUSR1 and SIGUSR2
- Receives binary data bit-by-bit through signals
- Reconstructs and prints characters as they are received
- Runs indefinitely until terminated
Signals Handled
Represents a binary
0 bit. The server shifts the current character left and adds 0.Represents a binary
1 bit. The server shifts the current character left and adds 1.Example Output
client
The client executable sends a string message to a running server process.Usage
Arguments
The process ID of the server. Must be a valid numeric PID.
The message to transmit to the server. Can contain any characters.
Exit Codes
Message sent successfully
Error occurred - invalid arguments, wrong PID format, or signal sending failed
Example
Core Functions
send_message
Sends a string message to a process by transmitting each character bit-by-bit using UNIX signals.Parameters
The process ID of the target server process
Pointer to the null-terminated string to send
Return Value
Success - all signals were sent successfully
Failure -
kill() returned -1, indicating signal sending failedBehavior
- Iterates through each character in the string
- For each character, sends 8 bits from most significant to least significant
- Sends SIGUSR2 for bit value 1, SIGUSR1 for bit value 0
- Uses 700 microsecond delay between signals (via
usleep(700)) - Returns immediately on first
kill()error
Implementation Example
handle_sigusr
Signal handler that receives individual bits and reconstructs characters.Parameters
The signal number received (SIGUSR1 or SIGUSR2)
Behavior
- Maintains static variables to track current character (
c) and bit count (i) - On SIGUSR1: shifts current character left (adds 0 bit)
- On SIGUSR2: shifts current character left and sets LSB to 1 (adds 1 bit)
- After receiving 8 bits, prints the complete character using
ft_printf - Resets counters after printing each character
Implementation Example
ft_atoi
Converts a string to an integer.Parameters
The string to convert. May contain leading whitespace and an optional +/- sign.
Return Value
The converted integer value, with sign applied if present
Behavior
- Skips leading whitespace (spaces and characters 9-13: tab, newline, etc.)
- Handles optional ’+’ or ’-’ sign
- Converts consecutive digits to integer
- Stops at first non-digit character
- Returns signed result
Implementation Example
ft_printf
Formatted output function similar to standard printf.Parameters
Format string with conversion specifiers
Variable arguments corresponding to format specifiers
Return Value
Number of characters printed
Supported Format Specifiers
%c- Character%s- String%d/%i- Signed decimal integer%u- Unsigned decimal integer%x- Hexadecimal lowercase%X- Hexadecimal uppercase%p- Pointer address