Technische Universität Braunschweig
  • Study & Teaching
    • Beginning your Studies
      • Prospective Students
      • Degree Programmes
      • Application
      • Fit4TU
      • Why Braunschweig?
    • During your Studies
      • Fresher's Hub
      • Term Dates
      • Courses
      • Practical Information
      • Beratungsnavi
      • Additional Qualifications
      • Financing and Costs
      • Special Circumstances
      • Health and Well-being
      • Campus life
    • At the End of your Studies
      • Discontinuation and Credentials Certification
      • After graduation
      • Alumni*ae
    • For Teaching Staff
      • Strategy, Offers and Information
      • Learning Management System Stud.IP
    • Contact
      • Study Service Centre
      • Academic Advice Service
      • Student Office
      • Career Service
  • Research
    • Research Profile
      • Core Research Areas
      • Clusters of Excellence at TU Braunschweig
      • Research Projects
      • Research Centres
      • Professors‘ Research Profiles
    • Early Career Researchers
      • Support in the early stages of an academic career
      • PhD-Students
      • Postdocs
      • Junior research group leaders
      • Junior Professorship and Tenure-Track
      • Habilitation
      • Service Offers for Scientists
    • Research Data & Transparency
      • Transparency in Research
      • Research Data
      • Open Access Strategy
      • Digital Research Announcement
    • Research Funding
      • Research Funding Network
      • Research funding
    • Contact
      • Research Services
      • Academy for Graduates
  • International
    • International Students
      • Why Braunschweig?
      • Degree seeking students
      • Exchange Studies
      • TU Braunschweig Summer School
      • Refugees
      • International Student Support
    • Going Abroad
      • Studying abroad
      • Internships abroad
      • Teaching and research abroad
      • Working abroad
    • International Researchers
      • Welcome Support
      • PhD Studies
      • Service for host institutes
    • Language and intercultural competence training
      • Learning German
      • Learning Foreign Languages
      • Intercultural Communication
    • International Profile
      • Internationalisation
      • International Cooperations
      • Strategic Partnerships
      • International networks
    • International House
      • About us
      • Contact & Office Hours
      • News and Events
      • International Days
      • 5th Student Conference: Internationalisation of Higher Education
      • Newsletter, Podcast & Videos
      • Job Advertisements
  • TU Braunschweig
    • Our Profile
      • Aims & Values
      • Regulations and Guidelines
      • Alliances & Partners
      • The University Development Initiative 2030
      • Foundation University
      • Facts & Figures
      • Our History
    • Career
      • Working at TU Braunschweig
      • Vacancies
    • Economy & Business
      • Entrepreneurship
      • Friends & Supporters
    • General Public
      • Check-in for Students
      • The Student House
      • Access to the University Library
    • Media Services
      • Communications and Press Service
      • Services for media
      • Film and photo permits
      • Advices for scientists
      • Topics and stories
    • Contact
      • General Contact
      • Getting here
  • Organisation
    • Presidency & Administration
      • Executive Board
      • Designated Offices
      • Administration
      • Committees
    • Faculties
      • Carl-Friedrich-Gauß-Fakultät
      • Faculty of Life Sciences
      • Faculty of Architecture, Civil Engineering and Environmental Sciences
      • Faculty of Mechanical Engineering
      • Faculty of Electrical Engineering, Information Technology, Physics
      • Faculty of Humanities and Education
    • Institutes
      • Institutes from A to Z
    • Facilities
      • University Library
      • Gauß-IT-Zentrum
      • Professional and Personnel Development
      • International House
      • The Project House of the TU Braunschweig
      • Transfer Service
      • University Sports Center
      • Facilities from A to Z
    • Equal Opportunity Office
      • Equal Opportunity Office
      • Family
      • Diversity for Students
  • Search
  • Quicklinks
    • People Search
    • Webmail
    • cloud.TU Braunschweig
    • Messenger
    • Cafeteria
    • Courses
    • Stud.IP
    • Library Catalogue
    • IT Services
    • Information Portal (employees)
    • Link Collection
    • DE
    • EN
    • IBR YouTube
    • Facebook
    • Instagram
    • YouTube
    • LinkedIn
    • Mastodon
Menu
  • Organisation
  • Faculties
  • Carl-Friedrich-Gauß-Fakultät
  • Institutes
  • Institute of Operating Systems and Computer Networks
  • Prof. Dr.-Ing. Christian Dietrich
  • Advent(2)
  • Santas Postbox (2)
Logo IBR
IBR Login
  • Institute of Operating Systems and Computer Networks
    • News
    • About us
      • Whole Team
      • Directions
      • Floor Plan
      • Projects
      • Publications
      • Software
      • News Archive
    • Connected and Mobile Systems
      • Team
      • Courses
      • Theses
      • Projects
      • Publications
      • Software
      • Datasets
    • Reliable System Software
      • Overview
      • Team
      • Teaching
      • Theses & Jobs
      • Research
      • Publications
    • Algorithms
      • Team
      • Courses
      • Theses
      • Projects
      • Publications
    • Microprocessor Lab
    • Education
      • Winter 2025/2026
      • Summer 2025
      • Theses
    • Services
      • Library
      • Mailinglists
      • Webmail
      • Knowledge Base
      • Wiki
      • Account Management
      • Services Status
    • Spin-Offs
      • Docoloc
      • bliq (formerly AIPARK)
      • Confidential Technologies
    • Research Cooperations
      • IST.hub
  • Task Overview
  • Git repository
  • Mailing list
  • Matrix-Channel

Santas Postbox (2)

☃️
Git-Repository: Template Solution Solution-Diff (Solution is posted at 18:00 CET)
Workload: 118 lines of code
Important System-Calls: signalfd(2), signal(7), mq_overview(7), mq_open(2), mq_timedreceive(2)
Recommended Reads:
  • Dec. 10: Pipes Full of Gravy ipc 131 lines [epoll_create(2), epoll_ctl(2), epoll_wait(2), pipe(7), splice(2)]
  • Dec. 12: Santa's Postbox ipc 74 lines [fifo(7), unix(7), mknod(2)]
Illustration for this exercsie

Now look at this, the postbox is already half finished. We only have to extend it with a few more exotic options for those children with very special ways to express their wishes in rather unusual ways. With these extensions, Santa's postbox will be truly versatile and future proof for the coming years of digitalization.

Signalfd and sigqueue

Usually, signal(7)s in a Linux program are similar to interrupts on the bare machine: At any point in time, the underlying execution engine (OS or CPU respectively) invokes the (signal/interrupt) handler function asynchronously. The handler interrupts the thread's control flow and resumes it on return in such a way that it's transparent for the executing control flow. This "everywhere and every time" comes at the cost that we have to think about signal-safety(7).

When you think of Unix signals, you usually only think about the signal numbers that are invoked without any kind of payload. However, with rt_sigqueueinfo(2), the signal sender can attach one 32-bit word of information to the target process, whereby we can use it as an incoming port of our postbox! What a happy day! We only want to look at the receiving side; you can send signals with a payload with the shell command kill(1):

/bin/kill -USR1 --queue 3 PID

On the receiving side, the queue payload can be extracted from the siginfo_t when using a normal signal handler that was installed with sigaction(2). However, for our postbox, we want to integrate the signal handling with our epoll-based framework, whereby we also avoid all problems regarding signal safety. For this we will use a signalfd(2):

int signalfd(int fd, const sigset_t *mask, int flags);

A signal file descriptor is a special kind of descriptor that will produce struct signalfd_siginfo objects when we read() from it, if our thread received a signal. The signalfd will listen only for those signals that are indicated by the given signal set mask.

Once you have properly integrated a singalfd for SIGUSR1 and for SIGUSR2, the postbox can now also output received signals with payload:

signalfd[uid=1419804,pid=10104] signal=10, data=3

POSIX Message Queues

While children that use sigqueue() have to have short, very short, indeed only 32-bit long wishes, POSIX message queues (mq_overview(7)) allow for much longer wish lists. This IPC mechanism is less known but has the unique properties that the message queue is independent from the existence of a process and it can outlive the creating process. Thereby, a sender can send a message to a message queue, even if the receiving process has not been started yet or is currently restarting. If the send operation succeeds, the sender knows that his message can be read by the receiver at some point in time. Perfect for Santa's postbox, that in its current work-in-progress state, is more often in the workshop than outside.

In essence, message queues are special files that we create with mq_open(2) and that become visible under /dev/mqueue unless we explicitly delete the message again with mq_unlink(3). For the rendezvous message queues use symbolic names, like FIFOs and domain sockets. With a look at /dev/mqueue/NAME, we can see the state of a message queue (postbox being the symbol NAME):

$ ./mq_send XYZ
$ cat /dev/mqueue/postbox
QSIZE:3          NOTIFY:0     SIGNO:0     NOTIFY_PID:0  box

Here we see that the queue has three bytes (XYZ) pending queue. That our postbox process can receive with mq_timedreceive(2) on start:

$ ./postbox
...
mqueue[prio=0]: XYZ

Tasks

Today's task is to integrate both the signalfd and the mqueue mechanism in our postbox from yesterday.

Hints

  • Both signalfd and mqueue descriptors can be registered with epoll and therefore be integrated in our postbox.
  • Use O_RDONLY | O_CREAT as flags for the mq_open as you not know if you are the first postbox process after the system boot.
  • You should block those signals with sigprocmask(2) that you wish to receive via an signalfd.

Last modified: 2023-12-01 15:52:27.972084, Last author: , Permalink: /p/advent-13-postbox


last changed 2023-12-01, 15:52 by Prof. Dr.-Ing. Christian Dietrich

For All Visitors

Vacancies of TU Braunschweig
Career Service' Job Exchange 
Merchandising

For Students

Term Dates
Courses
Degree Programmes
Information for Freshman
TUCard

Internal Tools

Glossary (GER-EN)
Change your Personal Data

Contact

Technische Universität Braunschweig
Universitätsplatz 2
38106 Braunschweig

P. O. Box: 38092 Braunschweig
GERMANY

Phone: +49 (0) 531 391-0

Getting here

© Technische Universität Braunschweig
Imprint Privacy Accessibility