A terminal-based interactive chatbot application built in C++ that demonstrates operating system concepts including process management, inter-process communication, file I/O, and terminal multiplexing using tmux.
This chatbot application runs in a tmux session and displays answers in separate terminal panes. It features conversation management with persistent storage, question-answer matching, and an interactive command-line interface.
- Interactive Q&A system with hardcoded knowledge base
- Tmux-based split panel for displaying answers
- Conversation persistence with file I/O operations
- Load and continue previous conversations
- Auto-detection and installation of dependencies
- Clean architecture with separated concerns
- Language: C++ (C++11 or later)
- Build System: g++ compiler with manual compilation
- Terminal Multiplexer: tmux for panel management
- Platform: Linux (POSIX-compliant systems)
<iostream>- Input/output operations<fstream>- File stream operations<string>- String handling<vector>- Dynamic arrays<map>- Key-value storage for Q&A pairs<cstdlib>- System command execution<ctime>- Timestamp generation<unistd.h>- POSIX API for process management<sys/wait.h>- Process control<sys/stat.h>- File/directory status<dirent.h>- Directory operations
chatbot-cpp/
├── main.cpp # Entry point and main application loop
├── include/ # Header files
│ ├── chatbot.hpp # Q&A matching and command handling
│ ├── conversation.hpp # Conversation storage and retrieval
│ ├── tmux_manager.hpp # Tmux session and panel management
│ └── utils.hpp # Utility functions (string processing)
├── bin/ # Compiled executables
│ └── chatbot
├── conversations/ # Saved conversation files
└── run.sh # Build and dependency management script
-
Process Management
readlink("/proc/self/exe", ...)- Get current executable pathexit(0)- Terminate processgetenv("TMUX")- Read environment variablessystem()- Execute shell commands
-
File and Directory Operations
mkdir(path, 0755)- Create directory with permissionsopendir()- Open directory streamreaddir()- Read directory entriesclosedir()- Close directory streamstat()- Get file/directory status
-
File I/O
std::ofstream- Write to files (conversation storage)std::ifstream- Read from files (conversation loading)- File operations for temporary data storage (
/tmp/chatbot_answer.txt)
-
Tmux Commands (via system())
tmux new-session -s <name>- Create new tmux sessiontmux has-session -t <name>- Check if session existstmux kill-session -t <name>- Terminate tmux sessiontmux split-window -h- Split window horizontallytmux list-panes- List all panes in sessiontmux kill-pane -t <id>- Close specific panetmux send-keys -t <id>- Send keyboard input to pane
-
Shell Commands
clear- Clear terminal screencat- Display file contentsgrep- Pattern matching for pane detection
The run.sh script is a comprehensive build and dependency management tool that handles:
-
Dependency Detection and Installation
- Automatically detects the system's package manager (apt-get, dnf, yum, pacman, zypper)
- Checks for g++ compiler and tmux installation
- Installs missing dependencies with appropriate package manager commands
-
Compilation
- Compiles the C++ source code with include directory flags
- Places the executable in the
bin/directory
-
Execution
- Automatically runs the compiled chatbot application
# Detects package manager
command -v apt-get &> /dev/null
# Installs dependencies
sudo apt-get install -y g++
sudo apt-get install -y tmux
# Compiles the project
g++ -I./include main.cpp -o bin/chatbot
# Runs the application
./bin/chatbot- Linux operating system
- Root/sudo access for package installation (first run only)
- Clone the repository:
git clone <repository-url>
cd chatbot-cpp- Make the script executable:
chmod +x run.sh- Run the application:
./run.shThe script will automatically:
- Detect your package manager
- Install g++ if not present
- Install tmux if not present
- Compile the source code
- Launch the chatbot in a tmux session
If you prefer manual compilation:
# Create bin directory if it doesn't exist
mkdir -p bin
# Compile
g++ -I./include main.cpp -o bin/chatbot
# Run in tmux
tmux new-session -s chatbot_session "./bin/chatbot"Type help in the chatbot to see all available commands:
help- Display help messagelist question- List all available questionsload question <n>- Load and display a question by numberlist convo- View saved conversationsload convo <n>- Load and continue a conversation by numbersave- Save the current conversationnew- Start a new conversationclear- Clear the screenclose- Close the answer panelexit- Quit the application
The chatbot can answer questions about:
- C++ programming language
- Tmux terminal multiplexer
- Process management (fork, exec)
- Inter-process communication (pipes, FIFO)
- Multithreading
- Shared resources
- Operating system concepts
Conversations are automatically saved to the conversations/ directory with:
- Timestamps for each message
- Conversation title (auto-generated or user-specified)
- Full message history
- Support for loading and continuing previous conversations
- Modular Design: Separate headers for distinct functionality
- Object-Oriented: Classes for Chatbot, TmuxManager, and Conversation
- Clean Separation: Business logic separated from UI and storage
- Terminal Multiplexing: Uses tmux for advanced terminal management
- File System Operations: Directory creation, file I/O, and persistence
- Process Control: Session management and cleanup
- Environment Interaction: Reading environment variables and executing system commands
This project is provided as-is for educational purposes demonstrating operating system concepts in C++.