Interprocess Signalling in Raspberry Pi

The Raspberrypi is a mini-computer board which is powerful enough to run large operating systems like Linux, Mac and Windows. The Raspberrypi is called a mini-computer because the SoC has the powerful ARM11 processor which runs on 700 MHz at its core and having the peripherals like timers, interrupt controller, GPIO, PCM / I2S, DMA controller, I2C, SPI slave, PWM, UART, USB, graphical processing unit (GPU) which includes VideoCore, MPEG-2 and MPEG-4 and a 512 MB SDRAM.

Linux operating systems especially Ubuntu is preferred for all kind of programming and development. The Raspberrypi is a board actually designed for helping computer education for remote schools but it is a nice platform for programmers especially beginners to explore various coding techniques. The immediate advantage of having an Operating System like Ubuntu running on an embedded system device is multitasking.

Interprocess Signalling in Raspberry Pi

In this project the Raspberrypi board is loaded with Ubuntu and is remotely accessed using VNC. The Raspberrypi board is also connected to the internet. There are 26 connectors which can be taken out from the connector port of the Raspberrypi board. All the connector pins are taken out using 13*2 pin female connectors and at the other end of their wire 26 pin Burg stick male connectors are attached. The Burg stick male connectors allow each pin out from the Raspberrypi board to be plugged into the holes of a breadboard.  To access the pins that coming out of the Broadcom controller of the Raspberrypi board using C language, a C library is available called “bcm2835” which has been downloaded and installed.

A signal is sent for the purpose of notifying the process about something that required immediate attention. Different signals are used to notify different events and the signals are differentiated by their signal numbers. The list of all the available signals in the OS and their signal numbers can be obtained using the following command:

kill -l

The following table gives a list of the most common signals that a process might encounter in an Operating System:

 NAME NUMBER DESCRIPTION
SIGHUP 1 Linux sends a process this signal when it becomes disconnected from a terminal.
SIGINT 2 Linux sends a process this signal when the user tries to end it by

pressing CTRL+C.

SIGILL 4 Linux sends a process this signal when it attempts to execute an illegal instruction.
SIGABRT 6 Linux sends a process this signal to the process when the process calls the ‘abort ()’ function
SIGFPE 8 Linux sends a process this signal when it has executed an invalid floating-point math instruction
SIGKILL 9 Linux sends a process this signal to end it immediately
SIGUSR1 10 User programs can send this signal to other process
SIGUSR2 12 User programs can send this signal to other process
SIGSEGV 11 Linux sends a process this signal when the program has attempted an invalid memory access
SIGPIPE 13 Linux sends a process this signal when the program has attempted to access a broken data stream, such as a socket connection that has been already closed
SIGALRM 14 A process can receive this signal from the Linux using the function alarm(), after a time period mentioned in its argument.
SIGTERM 15 Linux sends a process this signal requesting it to terminate
SIGCHLD 17 Linux sends a process this signal when a child process exits
SIGXCPU 24 Linux sends a process this signal when it exceeds the limit of

CPU time that it can consume.

SIGVTALRM 26 A process can receive this signal from the Linux using the function setitimer (), after a time period mentioned in its argument.

In this project a Parent process creates so many Child process and controls them using the signal 12 which is the ‘SIGUSR2’. The two signals ‘SIGUSR1’ and the ‘SIGUSR2’ are reserved for the user applications and hence they can be used in this project also.

In this particular project a Parent creates 8 Childs process which are then used to control 8 LEDs connected to the IO pins of the Raspberrypi board.  The Child processes are then made to change the glowing state of the LED by sending ‘SIGUSR2’ signal. This forms a Process System made up of several Child process and a Parent process and the entire system is controlled by the Parent process.

#include <bcm2835.h>
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#define PIN1 RPI_GPIO_P1_11
#define PIN2 RPI_GPIO_P1_12
#define PIN3 RPI_GPIO_P1_24
#define PIN4 RPI_GPIO_P1_15
#define PIN5 RPI_GPIO_P1_16
#define PIN6 RPI_GPIO_P1_18
#define PIN7 RPI_GPIO_P1_22
#define PIN8 RPI_GPIO_P1_07
void set_pins_output ( void );
void set_all_pin_low ( void );
void toggle1_on_signal_rx ( void );
void toggle2_on_signal_rx ( void );
void toggle3_on_signal_rx ( void );
void toggle4_on_signal_rx ( void );
void toggle5_on_signal_rx ( void );
void toggle6_on_signal_rx ( void );
void toggle7_on_signal_rx ( void );
void toggle8_on_signal_rx ( void );
 Interprocess Signalling in Raspberry Pi Schematic
void toggle1_sig_handler ( int signo );
void toggle2_sig_handler ( int signo );
void toggle3_sig_handler ( int signo );
void toggle4_sig_handler ( int signo );
void toggle5_sig_handler ( int signo );
void toggle6_sig_handler ( int signo );
void toggle7_sig_handler ( int signo );
void toggle8_sig_handler ( int signo );
pid_t child_id [ 8 ];
int main ( void )
{int i; if (!bcm2835_init())
return 1;set_pins_output ();
set_all_pin_low (); if ( ! ( child_id [ 0 ] = fork () ) )
{toggle1_on_signal_rx ();_exit ( 0 );}else; if ( ! ( child_id [ 1 ] = fork () ) )
{toggle2_on_signal_rx ();_exit ( 0 );}else; if ( ! ( child_id [ 2 ] = fork () ) )
{toggle3_on_signal_rx ();_exit ( 0 );}else; if ( ! ( child_id [ 3 ] = fork () ) )
{toggle4_on_signal_rx ();_exit ( 0 );}else;if ( ! ( child_id [ 4 ] = fork () ) )
{toggle5_on_signal_rx ();
_exit ( 0 );}else;

For more detail: Interprocess Signalling in Raspberry Pi


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top