12 Signals, interrupts, and exceptions

 

This chapter covers

  • What interrupts, exceptions, traps, and faults are
  • How device drivers inform applications that data is ready
  • How to transmit signals between running applications

This chapter describes the process by which the outside world communicates with your operating system (OS). The network constantly interrupts program execution when bytes are ready to be delivered. This means that after connecting to a database (or at any other time), the OS can demand that your application deal with a message. This chapter describes this process and how to prepare your programs for it.

In chapter 9, you learned that a digital clock periodically notifies the OS 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 OS tradition. These can be used to send messages between different running programs.

We’ll address both concepts—signals and interrupts—together, as the programming models are similar. But it’s simpler to start with signals. Although this chapter focuses on the Linux OS running on x86 CPUs, that’s not to say that users of other operating systems won’t be able to follow along.

12.1 Glossary

12.1.1 Signals vs. interrupts

12.2 How interrupts affect applications

12.3 Software interrupts

12.4 Hardware interrupts

12.5 Signal handling

12.5.1 Default behavior

12.5.2 Suspend and resume a program’s operation

12.5.3 Listing all signals supported by the OS

12.6 Handling signals with custom actions

12.6.1 Global variables in Rust

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

12.7 Sending application-defined signals

12.7.1 Understanding function pointers and their syntax

12.8 Ignoring signals

12.11 Revising exceptions