Project 4: POSIX Message Queue Priority Dispatcher

A job dispatcher that uses POSIX message queue priorities to ensure high-priority jobs are processed first.

Quick Reference

Attribute Value
Primary Language C
Alternative Languages Rust
Difficulty Level 3 (Advanced)
Time Estimate See main guide
Knowledge Area IPC, Task Scheduling
Tooling See main guide
Prerequisites See main guide

What You Will Build

A job dispatcher that uses POSIX message queue priorities to ensure high-priority jobs are processed first.

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Priority inversion → Low-priority jobs starving
  • Queue full handling → What to do when mq_send blocks
  • Async notification → Using mq_notify for efficiency

Key Concepts

  • Map the project to core concepts before you code.

Real-World Outcome

# Start the dispatcher
$ ./job_dispatcher &
Dispatcher running, queue: /job_queue

# Submit jobs with different priorities
$ ./submit_job --priority=0 --cmd="sleep 10"  # Low priority
Job 1 queued (priority 0)

$ ./submit_job --priority=31 --cmd="echo URGENT"  # High priority
Job 2 queued (priority 31)

$ ./submit_job --priority=15 --cmd="date"  # Medium priority
Job 3 queued (priority 15)

# Watch dispatcher output - processes high priority first!
Dispatcher: Processing job 2 (priority 31): echo URGENT
URGENT
Dispatcher: Processing job 3 (priority 15): date
Sat Jan  1 12:00:00 UTC 2025
Dispatcher: Processing job 1 (priority 0): sleep 10
(10 seconds later...)

Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: UNIX_IPC_STEVENS_VOL2_MASTERY.md
  • Primary references are listed in the main guide