Skip to content

samuelhm/Minitalk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minitalk

C Language 42 Barcelona Architecture IPC Score

Systems Programming Signal Handling Concurrency Low Level


Overview

Minitalk is a UNIX inter-process communication (IPC) project that demonstrates mastery of systems programming through signal-based message transmission. The project implements a robust client-server architecture where text messages are encoded bit-by-bit and transmitted using only SIGUSR1 and SIGUSR2 signals—no sockets, pipes, or shared memory required.


Features

  • Binary message encoding: 8 bits per character
  • Multi-client support: Handles up to 500 concurrent clients simultaneously
  • Acknowledgment protocol: Client-server handshake ensures reliable transmission
  • Timeout mechanism: Prevents deadlocks from unresponsive processes
  • Clean memory management: No leaks, proper resource cleanup
  • Modular library integration: Uses custom libft static library
  • Bonus version with enhanced functionality

Tech Stack

Category Technology
Language C (C99 standard)
IPC Mechanism Unix Signals (SIGUSR1, SIGUSR2)
System Calls kill(), pause(), sigaction(), usleep()
Build System Makefile with dependency tracking
Library libft - Custom C standard library

Architecture Decision

The decision to use Unix signals for IPC instead of traditional sockets or pipes addresses a fundamental systems programming challenge: minimal overhead communication between processes. Signals operate at the kernel level, requiring no buffer allocation or file descriptors. Each character is decomposed into 8 bits and transmitted sequentially where SIGUSR1 represents bit 1 and SIGUSR2 represents bit 0. The acknowledgment protocol (server echoes SIGUSR1 per bit received) ensures synchronization without race conditions, while static arrays manage client state across multiple concurrent connections—a pattern demonstrating practical understanding of process isolation and signal-safety constraints.


Architecture Diagram

flowchart TD
subgraph Client["CLIENT PROCESS"]
    A[Start] --> B[Parse PID + Message]
    B --> C[Encode Character to Bits]
    C --> D{Each Bit}
    D -->|Bit = 1| E[Send SIGUSR1]
    D -->|Bit = 0| F[Send SIGUSR2]
    E --> G[Wait for ACK]
    F --> G
    G --> H{ACK Received?}
    H -->|Yes| I[Next Bit]
    H -->|Timeout| J[Resend Bit]
    I --> D
    J --> D
end

subgraph Server["SERVER PROCESS"]
    K[Start] --> L[Print PID + Listen]
    L --> M[Signal Handler]
    M --> N{New or Known Client?}
    N -->|New| O[Register Client]
    N -->|Known| P[Update Client Buffer]
    O --> P
    P --> Q{8 Bits Received?}
    Q -->|No| R[Send ACK SIGUSR1]
    Q -->|Yes| S{Null Terminator?}
    S -->|No| T[Append to String]
    S -->|Yes| U[Print Message + Clean]
    T --> R
    U --> V[Release Client Slot]
    R --> M
end

Client -.->|kill PID SIGUSR1/SIGUSR2| Server
Server -.->|kill PID SIGUSR1 ACK| Client
Loading

Getting Started

Prerequisites

  • GCC or Clang compiler
  • Make build tool
  • Unix-like system (Linux/macOS)

Installation

git clone https://github.com/samuelhm/Minitalk.git
cd Minitalk
make

This compiles both server and client executables. For the bonus version:

make bonus

Usage

Terminal 1 - Start the server:

./server
# Output: Server PID: <PID>

Terminal 2 - Send a message:

./client <SERVER_PID> "Your message here"

Testing

Run the provided test script for sequential and async tests:

./server &
./test.sh

Project Structure

Minitalk/
├── Makefile           # Build configuration
├── include/
│   ├── minitalk.h      # Main header
│   └── minitalk_bonus.h# Bonus header
├── src/
│   ├── server.c        # Server implementation
│   ├── client.c        # Client implementation
│   ├── server_bonus.c  # Bonus server
│   └── client_bonus.c  # Bonus client
├── lib/
│   └── libft/          # Custom C library (submodule)
└── test.sh             # Test script

Contact

Platform Link
GitHub github.com/samuelhm
LinkedIn linkedin.com/in/shurtado-m

Built as part of the 42 Barcelona curriculum

About

El propósito de este proyecto es crear un pequeño programa de intercambio de datos utilizando señales UNIX

Resources

Stars

Watchers

Forks

Releases

No releases published

Contributors