Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to Control a Process Through Signal -(Part 18/38)

By Ajish Alfred September 9, 2013

The Raspberry pi is a device which uses the Broadcom controller chip which is a SoC (System on Chip). This SoC has the powerful ARM11 processor which runs on 700 MHz at its core. This powerful processor and the controller 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 makes it a mini-computer. The Raspberrypi board is powerful enough to run large operating systems like Linux, Mac and Windows.

Linux operating systems especially Ubuntu is preferred for all kind of programming and development. The operating systems like Archlinux ARM, OpenELEC, Pidora, Raspbmc, RISC OS and the Raspbian and also Ubuntu versions are available for the Raspberrypi board. The Raspberrypiis 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 like Raspberrypiis Multi-User-Multitasking. The Multi-tasking means the OS can run several processes at a time creating and effect of parallel processing with the help of the high speed processor. This article discusses how to control a process which is in running state using ‘signals’.

 


 

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 a software interrupt that can be sent to a process which is currently executing in the Operating System. Most of the time the Operating system send signals to the processes, but process can also send signals to each other. Much like hardwareinterrupts it is a mechanism to notify a process that an event has occurred. 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.

 Fig. 2: List of common signals for controlling process through signal in Operating System

Few of the above signals will end the receiving process immediately, but the rest of them the process can consider them and do the required things.The steps that the process do corresponding to a received signal is called ‘Signal Handling’. It is very much similar to the ‘Interrupt Servicing’ and just like the ‘Interrupt Service Routine’, there should be a function called ‘Signal Handler’ which can perform the necessary things in response to a signal received.

A function can be made the Signal Handler for a particular signal using the function called ‘signal ()’ and the details of the same function are mentioned below;

signal ()

The signal is a function which assigns another function as a Signal Handler for a particular signal. The prototype of the function is declared in the header file <signal.h> as;

void ( *signal(int sig, void (*handler)(int)) ) (int);

From the above prototype, it can be make out that the function signal () can receive an integer, which is the signal number provided by the OS. The function has two arguments also. The first argument is an integer which refers to the signal number to be handled when received. The second argument is a pointer to the function which needs to be act as a signal handler. The function that needs to be acts as a signal handler should have the capability to receive an integer as its argument. The function returns the same function pointer.

Assume a function; say ‘sig_handler’ is declared as follows;

voidsig_handler ( intsigno );

To make a function ‘sig_handler’ as a Signal Handler for the signal number ‘2’, use the ‘signal ()’ function as given below;

int main()

{

signal ( 2, sig_handler );

 

            while ( 1 ); 

}

 

The code will wait till the signal number 2, (SIGINT) is received and as soon as the SIGINT is received the signal number is passed to the function ‘sig_handler()’  and also the statements written inside the function ‘sig_handler()’ will get executed.

The SIGINT can be easily generated using the CTRL+C in the terminal where the program is being executed. It is suggested to write a simple

printf ( “nhellon” );

Statement inside the ‘sig_handler()’ function and try to print it by pressing CTRL+C.

The code written for this project receives the SIGINT and blinks the LEDs using the ‘sig_handler()’ function.

*******************************************************************************
Note:
In this project the Raspberrypi board version 2 is used, but a previous version of the “bcm2835” library is installed. Accessing the GPIO pin 13 is not possible with this library and hence the 3rd IO pin is selected as pin24 of the P1 port of the Raspberrypi. The circuit and the code are modified accordingly. Those who have the version 2 of the Raspberrypi and the latest version of the “bcm2835” library can use the GPIO pin 13 using “RPI_V2_GPIO_P1_13” instead of “RPI_GPIO_P1_13” in the pin definition.
For example to define a ‘PIN’ as 13th pin of P1 port of Raspberrypi board version2, use the following statement in the code;
#define PIN RPI_V2_GPIO_P1_13
 
 

 

*******************************************************************************

Project Source Code

###


 
#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 sig_handler ( int signo );
void set_pins_output ( void );
void set_all_pin_low ( void );
 
int main()
{
 
if (!bcm2835_init())
return 1;
set_pins_output ();
set_all_pin_low ();
 
signal ( 2, sig_handler );
 
while ( 1 );  
 
bcm2835_close();
return 0;
}
 
void set_all_pin_low ( void )
{
bcm2835_gpio_write(PIN1, LOW);
bcm2835_gpio_write(PIN2, LOW);
bcm2835_gpio_write(PIN3, LOW);
bcm2835_gpio_write(PIN4, LOW);
bcm2835_gpio_write(PIN5, LOW);
bcm2835_gpio_write(PIN6, LOW);
bcm2835_gpio_write(PIN7, LOW);
bcm2835_gpio_write(PIN8, LOW);
}
 
void set_pins_output ( void )
{
bcm2835_gpio_fsel(PIN1, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN2, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN3, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN4, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN5, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN6, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN7, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN8, BCM2835_GPIO_FSEL_OUTP);
}
 
void sig_handler ( int signo )
{
static int i = 0;
 
set_all_pin_low ();
bcm2835_delay( 50 );
 
i ++;
 
switch ( i )
{
case  1:
bcm2835_gpio_write(PIN1, HIGH);
break;
case  2:
bcm2835_gpio_write(PIN2, HIGH);
break;
case  3:
bcm2835_gpio_write(PIN3, HIGH);
break;
case  4:
bcm2835_gpio_write(PIN4, HIGH);
break;
case  5:
bcm2835_gpio_write(PIN5, HIGH);
break;
case  6:
bcm2835_gpio_write(PIN6, HIGH);
break;
case  7:
bcm2835_gpio_write(PIN7, HIGH);
break;
case  8:
bcm2835_gpio_write(PIN8, HIGH);
i = 0;
break;
};
}
 

###

 


Project Components

  • LED
  • Resistor

Project Video


Filed Under: Raspberry pi
Tagged With: Raspberry Pi
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • i need an embedded c program that will read a 12 bit memory address from the io pins and output the data to pins from the memory in a 8051 mcontroller
  • DIY Buck Boost Converter using XL6019
  • Getting Started with Electronics: What Helped You the Most in the Beginning?
  • De-embedding using Y, Z parameter
  • Simple Active Bandpass Filter Oscillates

RSS Electro-Tech-Online.com Discussions

  • parallel-to-serial problem
  • 12v battery, 18v magic
  • STM32 checking self-written delay function
  • Behringer MX 1602 mixer - reading block diagram
  • Reclaiming missing motherboard header

Featured -USB Series

  • Controller Chip Selection for Developing USB Enabled Device (Part 6/6)
  • Signal and Encoding of USB System (Part 5/6)
  • USB Requests and Stages of Control Transfer (Part 4/6)
  • USB Descriptors and their Types (Part 3/6)
  • USB Protocol: Types of USB Packets and USB Transfers (Part 2/6)
  • Introduction to USB: Advantages, Disadvantages and Architecture (Part 1/6)

Recent Articles

  • Littelfuse driver achieves less than 1 µA standby current for energy-efficient designs
  • Microchip optimizes power consumption in transceiver-less FPGA design for automotive applications
  • What is an IoT platform and when is one useful?
  • Silanna launches laser driver IC with sub-2 ns FWHM pulse for LiDAR application
  • LEM introduces current sensors with bandwidth up to 2.5 MHz for precision applications

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe