Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minitalk

Inter-process communication using UNIX signals — a tiny client/server messaging system.

Language School Norm


About

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.


How It Works

Each character (8 bits) is transmitted bit by bit, LSB first:

  • SIGUSR1 represents a 0 bit
  • SIGUSR2 represents a 1 bit

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.


Structure

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

Usage

Build

make

Produces two binaries: server and client.

Step 1 — Start the server

./server

Output:

Server PID: 12345
Waiting for messages...

Step 2 — Send a message

In a second terminal:

./client 12345 "Hello, 42!"

The server prints:

Hello, 42!

Error Handling

  • 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

Makefile Targets

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

Notes

  • 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 libft used for output and argument parsing — no external dependencies.
  • Written in compliance with the 42 Norm.

42 Heilbronn — Core Curriculum

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages