12 Signals, Interrupts and Exceptions

 

In this chapter:

  • Learn how the outside world, such as the network and the keyboard, lets an application know that it has data ready for processing
  • Disambiguating between the terms interrupt, exception, trap and fault
  • Send and receive signals between running applications

This chapter describes the process by which the outside world communicates with your operating system. Programs' execution is constantly being interrupted by the network when bytes are ready to be delivered. That is, after connecting to a database—or at any other time—the operating system could demand that your application deals with a message. This chapter describes how this process operates and how to prepare your programs for it.

In the last chapter, you learned a digital clock is periodically notifying the operating system that time has progressed. This chapter explains how those notifications occur. It also introduces the concept of multiple applications running at the same time via the concept of signals.

Signals emerged as part of the UNIX operating system tradition and can be used to send messages between different running programs.

We’ll be addressing both concepts—signals and interrupts—together as the programming model is similar but it’s simpler to get started with signals.

This chapter tends to focus on the Linux operating system running on x86 CPUs. That’s not to say that uses of other operating systems are unable to do follow along.

12.1  Disambiguating several related terms

 
 

12.2  Avoiding writing code by relying on the default signal handling behavior

 
 
 
 

12.2.1  Using SIGSTOP and SIGCONT to suspend and resume a program’s operation

 
 
 

12.2.2  Listing all signals supported by the operating system

 
 
 

12.3  Handling signals with custom actions

 
 

12.3.1  Global variables in Rust

 
 

12.3.2  Using a global variable to indicate that shutdown has been initiated

 
 
 

12.4  Sending application-defined signals

 
 
 

12.4.1  Understanding function pointers and their syntax

 

12.5  Ignoring signals

 
 

12.6  Shutting down from deeply nested call stacks

 
 
 
 

12.6.1  Setting up intrinsics in a program

 
 

12.6.2  Casting a pointer to another type

 
 
 

12.6.3  Running the Linux-specific code from Listing 12.23 in other operating systems via Docker

 
 
 

12.6.4  Compiling the code

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest