This project consists in the development of a kernel module for Linux systems that implements the publisher-subscriber design pattern for inter-processes communication.
The module is the final result of Advanced Operating Systems course in Computer Science & Engineering Master Degree at Politecnico di Milano, Italy.
- Project supervisor: Federico Reghenzani
- Course head professor: Vittorio Zaccaria
- Student developers: Ottavia Belotti and Riccardo Izzo
From terminal, run the given Makefile in the project directory to compile the C source code into the psipc_kmodule.ko
kernel object file.
make
After compilation, to insert the module in the current system:
#optional: clean the kernel message buffer before insertion
sudo dmesg -C
sudo insmod psipc_kmodule.ko
Once it is not needed anymore, remove it with:
sudo rmmod psipc_kmodule
The module creates a tree-structure in the /dev directory that, once the module has been loaded succesfully, will resemble the one proposed below.
/dev/psipc/
|
|__ /new_topic
|__ /topics
|
|__ /my_topic_1
| |
| |__ /subscribe
| |__ /subscribers_list
| |__ /signal_nr
| |__ /endpoint
|
|__ /my_topic_2
. |
. .
. .
A user process that acts as a publisher has to request the creation of the desired topic by writing its name on the new_topic
file. The module creates a new directory in /dev/psipc/topics specific to that topic with all the necessary files related to it: subscribe
, subscribers_list
, signal_nr
and endpoint
.
Once this has been set up, other user processes running under the same user space as the creator of the topic can:
- Subscribe to the topic: write their PID in /subscribe. When a message is published for that topic, the subscriber will receive a signal (following POSIX standard), chosen by the publisher
- Retrieve a list of all the subscribers: read the /subscribers_list file to know the PIDs of all the processes currently subscribed to that topic
- Read the published message: read the last published message from /endpoint. This is allowed just for subscribed processes.
The publisher can:
- Choose a signal: choose a POSIX standard message by writing its number on /signal_nr file. Once the publisher write a new message, the signal will be sent to all the current subscribers of the topic. Writing more than once on /signal_nr overwrites the signal. If no signal is set, the module won't send anything to the subscribers.
Note: not setting a signal doesn't mean that the message can't be written. It just won't notify the subscribers.
- Publish a message: add a new message by writing it in /endpoint. If a signal has been set, the act of writing in here will notify the subscribers.
Note: A publisher can't write a new message if all the present notified subscribers have not read the previous one yet.
The module has been developed in Ubuntu 20.04 LTS distro with development tools on a Virtual Machine.
Kernel version: v5.11
- The Linux Kernel Module Programming Guide - by Peter Jay Salzman, Michael Burian, Ori Pomerantz, Bob Mottram, Jim Huang
- Linux - Linus Torvalds official repository on GitHub
- Bootlin Elixir Cross Referencer - to explore in an easier way the Linux source code
- Oracle VM VirtualBox