ChatterBox is a terminal-based multi-user chat application built using System V IPC mechanisms and POSIX threads. It's a perfect example of how operating system principles can be applied to create practical software!
- Process Communication using System V message queues
- Shared Memory using System V shared memory segments for chat logs
- Multi-threading with POSIX threads for concurrent operations
- Thread Synchronization using POSIX mutex for shared memory access
- Signal Handling for graceful shutdown and thread coordination
- Resource Management with proper cleanup procedures
- Non-blocking I/O with IPC_NOWAIT flag for robust communication
- GCC compiler
- Linux/Unix-based operating system (tested on Ubuntu)
- Make utility
# Clone the repository
git clone https://github.com/Frex22/OS-Project-DAK.git
cd OS-Project-DAK
# Build the server and client
make all./chat_serverThe server will start and display a prompt where you can enter commands:
list- Show all connected clientsquit- Shutdown the server
In separate terminal windows, start one or more clients:
./chat_client YourUsernameReplace YourUsername with your desired chat name.
Once connected, you can:
- Type any message to chat with everyone
- Type
logsto view chat history - Type
quitto disconnect
- 👥 Connect with multiple users simultaneously
- 📜 View chat history even if you just joined
- 🔔 Real-time message delivery
- ⏱️ Timestamps on all messages
- 🔐 System handles crashes gracefully
- 🌐 Distributed architecture that can run across multiple machines
┌─────────────┐ ┌──────────────┐
│ Client 1 │◄─────► │ │
└─────────────┘ │ │
│ Server │◄────► Shared Memory (Logs)
┌─────────────┐ │ │
│ Client 2 │◄─────► │ │
└─────────────┘ └──────────────┘
... ▲
│
┌─────────────┐ │
│ Client N │◄──────────────┘
└─────────────┘
- Server: Manages client connections and broadcasts messages
- Clients: Send and receive messages via their own message queues
- Shared Memory: Stores chat history accessible to all clients
ChatterBox leverages two key System V IPC mechanisms:
-
Message Queues:
- Server queue (central communication point)
- Individual client queues (one per connected client)
- Message types for different operations (connect, disconnect, chat)
- Non-blocking operations using IPC_NOWAIT flag
-
Shared Memory:
- 1MB shared memory segment for storing chat logs
- Flexible array member for dynamic buffer allocation
- Circular buffer implementation to manage memory usage
- Process-shared mutex for synchronization
The application uses multiple threads with specific responsibilities:
Server Threads:
- Message Receiver Thread: Handles incoming messages from all clients
- Log Sync Thread: Periodically writes chat logs to disk
Client Thread:
- Message Receiver Thread: Processes incoming messages in the background
- Process-shared POSIX Mutex: Protects the shared log buffer from concurrent access
- Thread Signaling: Uses SIGUSR1 signals to wake up blocked threads during shutdown
- Atomic Flag: The
runningvariable coordinates thread shutdown
- Non-blocking operations with proper error recovery
- Error classification (ENOMSG, EINTR, EIDRM, EINVAL)
- Graceful shutdown with resource cleanup sequence
- Client reconnection detection and management
Building this chat system demonstrates several important concepts:
- The power of IPC mechanisms for building distributed applications
- The importance of proper resource management
- How multi-threading can improve application responsiveness
- Techniques for robust error handling and recovery
Implemnted coded and created by
- Aakash: Ideation, Threads, Client logic
- Dev: Server, Syncronization, Cleanup Procedures
- Kush: Server, Shared Memory
Created with 💖 for Operating Systems enthusiasts everywhere!