Skip to content

Day57 - POSIX Message Queue IPC

Date

2026-05-18


Topics

  • POSIX message queue IPC
  • mq_open()
  • mq_send()
  • mq_receive()
  • mq_attr
  • message priority
  • blocking queue
  • non-blocking queue
  • mq_notify()
  • epoll + mqueue
  • timerfd integration
  • signalfd integration

Implemented

Basic POSIX mqueue IPC

Implemented:

  • independent sender
  • independent receiver
  • queue creation/open
  • blocking receive
  • message transmission

Queue Attribute Management

Explored:

  • mq_maxmsg
  • mq_msgsize
  • mq_curmsgs
  • mq_flags

Observed:

mq_receive() buffer size must >= mq_msgsize

Priority Queue

Implemented message priority.

Verified:

  • higher priority dequeued first
  • FIFO ordering inside same priority

Blocking Queue Behavior

Verified:

queue full -> mq_send() blocks
queue empty -> mq_receive() blocks

Non-Blocking Queue

Implemented:

O_NONBLOCK

Observed:

EAGAIN when queue full
EAGAIN when queue empty

mq_notify()

Implemented:

SIGEV_SIGNAL

notification.

Learned:

  • empty -> non-empty transition
  • one-shot registration
  • re-arm logic
  • queue drain pattern

epoll Integration

Integrated:

  • mqueue fd
  • timerfd
  • signalfd

into one epoll loop.


timerfd

Used timerfd for:

  • periodic queue statistics
  • mq_curmsgs monitoring

signalfd

Used signalfd for:

  • SIGINT
  • SIGTERM

graceful shutdown handling.


Key Learnings

POSIX Message Queue

Kernel-managed IPC:

  • synchronized by kernel
  • message-oriented
  • priority-aware

Linux Event Architecture

Compared:

mq_notify()

vs

epoll

POSIX vs Linux Style

mq_notify()

POSIX async notification model.


epoll

Linux fd readiness model.


Unified Event Loop

Final architecture:

epoll
 ├── mqueue
 ├── timerfd
 └── signalfd

This demonstrates modern Linux userspace middleware architecture.


Result

Successfully implemented a complete Linux POSIX message queue IPC demo with:

  • blocking/non-blocking operation
  • priority queue
  • async notification
  • epoll integration
  • timerfd/signalfd integration
  • unified Linux event loop