This project is an Operating Systems assignment that simulates a real-time chat management and moderation system for a dystopian regime. The system ensures all user conversations within chat groups are closely monitored, flagged, and moderated according to predefined rules.
The core objective is to build a multi-process, POSIX-compliant system using pipes and System V message queues for communication, demonstrating concepts of IPC, process management, message ordering, and moderation logic.
├── app.c # Main control process - spawns and tracks groups
├── groups.c # Simulates group chat behavior with user processes
├── moderator.c # Monitors messages for restricted content
├── validation.out # Intel/AMD/Older Mac (x64) validation binary
├── validation1.out # Mac M1 (AArch64) validation binary
├── testcases.zip # Testcase archive
├── image.png # Block diagram of the system
└── README.md # Project documentation (you are here!)
The system simulates a chat management and moderation framework where different entities—moderator, groups, and users—are represented as processes. Each group process corresponds to a chat group (like a WhatsApp group) consisting of multiple user processes. Users send messages to their group process via pipes. The group process monitors content for restricted words and interacts with the moderator and validation processes using message queues.
- Moderator: Checks messages for violations and bans users exceeding a threshold.
- Validation: Ensures message order and correct banning.
- App: Spawns group processes and tracks their termination.
Communication:
- Three System V message queues (group-app, group-moderator, group-validation)
- Unnamed pipes (user-group)
- Real-Time Monitoring: Tracks messages in real-time from multiple users and flags violations.
- Inter-Process Communication (IPC): Uses three System V message queues and unnamed pipes.
- Moderation Logic: Violations are detected based on substring matches of banned words.
- Dynamic User Handling: Users can be banned or removed based on violations or completion of all messages.
- Message Ordering: Ensures strict chronological order of message delivery.
- Robust Error Handling: Comprehensive checks for file reads, process creation, and IPC operations.
Requirements:
- Ubuntu 22.04 or 24.04 (recommended)
- GCC compiler
To compile the project:
gcc -o app.out app.c
gcc -o groups.out groups.c
gcc -o moderator.out moderator.c
chmod 777 validation.out # Only needed once
Run the following processes in three separate terminals (replace <testcase_number>
with your test case):
- Validation Process
./validation.out <testcase_number>
- Moderator Process
./moderator.out <testcase_number>
- App Process (Launcher)
./app.out <testcase_number>
Note: Do NOT run
groups.out
directly — it is automatically invoked byapp.out
.
- Red arrows: Message queue between group processes and app process
- Green arrows: App process spawns group processes
- Blue arrows: Message queue between group processes and moderator process
- Yellow arrows: Message queue between group processes and validation process
- Black arrows: Unnamed pipes between user processes and their group process
- Reads configuration from
input.txt
. - Spawns N group processes.
- Tracks termination of each group.
- Prints termination messages, e.g.:
All users terminated. Exiting group process X.
- Each group forks multiple user processes.
- Users read from their files and send messages via pipes.
- Group process:
- Sorts messages by timestamp.
- Forwards valid messages to
validation.out
. - Sends every message to the moderator.
- Bans users if notified.
- Terminates when users < 2.
- Loads restricted words from
filtered_words.txt
. - Performs case-insensitive substring match.
- Tracks and increments violation counts.
- Bans users if they exceed the violation threshold.
- Logs removal:
User X from group Y has been removed due to M violations.
testcase_<X>/
├── input.txt # Main config file
├── filtered_words.txt # Restricted words (one per line)
├── groups/
│ └── group_<id>.txt # Lists users in that group
└── users/
└── user_<group>_<id>.txt # Timestamped messages
3 # number of groups
3430 # validation queue key
4928 # app-group queue key
9131 # moderator queue key
5 # violation threshold
groups/group_0.txt
groups/group_3.txt
groups/group_7.txt
- Validation Message Types:
mtype = 1
→ New groupmtype = 2
→ New usermtype = 3
→ Group terminationmtype = 30+grp_num
→ Message from group
- Moderator Message Queue:
- Send from group:
mtype = 100 + grp_num
- Receive in group:
mtype = 300 + grp_num
- Send from group:
- Error Handling:
- Comprehensive checks for file reads,
fork()
,pipe()
,msgsnd()
, andmsgrcv()
.
- Comprehensive checks for file reads,
- No use of threads, mutexes, or shared memory.
- Must use only:
- Message Queues: for validation/app/moderator
- Unnamed Pipes: for user-to-group
- All input files are ASCII text.
- Must ensure correct closure of unused pipe ends.
- No use of
goto
statements.
- Max. number of groups per test case: 30
- Max. number of users per group: 50
- Max. number of filtered words: 50
- Max. length of a filtered word: 20
- Max. length of a line in users_X_Y.txt: 256 characters
- Max. message timestamp: 2147000000
- On user removal:
User from group has been removed due to violations.
- On group termination:
All users terminated. Exiting group process .
- On success:
Testcase passed: ...
- Validation Binary:
- Intel/AMD/Older Mac (x64): use
validation.out
- Mac M1 (AArch64): use
validation1.out
- Intel/AMD/Older Mac (x64): use
- Error Handling:
- Perform proper error handling for all system calls.
- File Specifications:
- All
.txt
files are ASCII (text-only) files.
- All
- IPC:
- Only pipes and message queues are allowed.
- Input Restrictions:
- No additional inputs beyond those specified.
- Synchronization and Multithreading:
- No mutexes, semaphores, or multithreading.
- Pipe Management:
- Close all unused pipe ends to prevent resource leaks.
- No unstructured programming constructs:
- Do not use
goto
.
- Do not use
- Arvind
Happy Coding! 🚀