A terminal-based chat system implemented as a custom Linux kernel module that enables user-space communication via character devices. This project demonstrates low-level IPC (Inter-Process Communication) and device driver programming using a producer-consumer model with blocking/non-blocking I/O operations.
⚙️ Note: This is a hobby project created for fun and learning.
- Kernel Module: Custom character device driver enabling chat functionality
- User-Space Client: Terminal-based chat client for communication
- Producer-Consumer Model: Efficient data handling with circular buffer
- Blocking/Non-blocking I/O: Supports both synchronous and asynchronous operations
- Multi-client Support: Multiple clients can connect simultaneously
- Memory Management: Proper kernel memory allocation and cleanup
The system consists of two main components:
-
kerneltalk_mod.c— Linux kernel module implementing:- Character device driver (
/dev/kerneltalk) - Circular buffer for message storage
- Client/server management per inode
- Synchronization using mutexes and wait queues
- Support for
select()andpoll()system calls
- Character device driver (
-
kerneltalk_client.c— User-space client providing:- Terminal interface for chat communication
- File descriptor multiplexing using
select() - Real-time message display and input
- Buffer Size: 2048 bytes circular buffer
- Synchronization: Read-write semaphores and mutexes
- Memory Management: Dynamic allocation with proper cleanup
- Device Operations:
open,close,read,write,poll - Multi-instance Support: Per-inode server instances
- Character Device:
/dev/kerneltalkserves as communication endpoint - Circular Buffer: Efficient message storage and retrieval
- Wait Queues: Blocking I/O implementation
- Select/Poll Support: Integration with standard I/O multiplexing
- Linux kernel headers for your current kernel version
- GCC compiler
- Root privileges for module installation
# Clone the repository
git clone https://github.com/thisizaro/KernelTalk.git
cd KernelTalk
# Build both kernel module and client
make all
# Install the kernel module (requires root)
sudo make install# Build kernel module
make module
# Build user-space client
make client
# Load the kernel module
sudo insmod kerneltalk_mod.ko
# Create device node
sudo mknod /dev/kerneltalk c $(grep kerneltalk /proc/devices | cut -d' ' -f1) 0
sudo chmod 666 /dev/kerneltalk# Terminal 1 - Start first client
./kerneltalk_client /dev/kerneltalk
# Terminal 2 - Start second client
./kerneltalk_client /dev/kerneltalkNow you can chat between the two terminals!
# Remove using Makefile
git clean -fdx
sudo make uninstall
# Or remove manually
sudo rmmod kerneltalk_mod
sudo rm -f /dev/kerneltalk-
Data Structures:
kerneltalk_server: Per-inode server managementkerneltalk_client: Per-process client tracking
-
Key Functions:
kerneltalk_open()– Device open handlerkerneltalk_read()– Message reading with blocking supportkerneltalk_write()– Message writing with flow controlkerneltalk_poll()– Select/poll support
-
Synchronization: Mutexes, read-write semaphores, and wait queues
- I/O Multiplexing: Uses
select()for real-time interaction - Buffer Management: Handles message buffering and display
- Error Handling: Comprehensive error checking and reporting
- Producer-Consumer Pattern: Classic synchronization model
- Circular Buffer: Efficient memory usage with wraparound logic
- Wait Queues: Proper blocking I/O implementation
- File Operations: Implements full character device interface
- Memory Safety: Careful allocation/deallocation practices
- Multi-client Architecture: Supports concurrent users seamlessly
- Developed on Linux kernel 4.x and later
- Follows Linux kernel coding standards
- Implements robust error handling and resource management
- Uses standard kernel APIs for character device driver development
- Language: C
- Environment: Linux Kernel
- Concepts: IPC, Character Devices, Producer-Consumer Synchronization
This project is licensed under the MIT License — see the LICENSE file for details.
Aranya Dutta thisizaro.official@gmail.com
Contributions are welcome! Please read the contributing guidelines (or open an issue) before submitting pull requests.