Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

L23 [Signals FSU]

Skyline-9 edited this page Nov 30, 2021 · 1 revision

IPC Mechanism

Signal tells a process that some event occurs

  • Examples: kill, SIGINT (Ctrl-C), SIGQUIT (Ctrl-), ... etc.

Available Actions and Signals

When a process receives a signal, it performs one of the following three options:

  • Ignore signal
  • Perform default operation
  • Catch the signal (perform a user defined operation)

Many signals are defined in signal.h

Processing Signals

  • similar to an interrupt (software interrupt)
  • when a process receives a signal:
    • pause execution
    • call the signal handler routine
    • Continue execution
  • Signal can be received at any point in the program
  • Most default signal handlers will terminate the program
  • You can change the way your program responses to signals

Simplified Signal Interface

#include <signal.h>
void (*signal(int sig, void (*disp)(int)))(int);

//Or alternatively
typedef void (*sighandler)(int);
sighandler signal(int sig, sighandler disp);

Semantics

  • sig: signal (defined in signal.h)
  • disp: SIG_IGN, SIGN_DFL or the address of the signal handler
  • Handler may be reset to SIG_DFL after one invocation

A call to signal() in C establishes the behavior for the process when it receives a particular signal

Signals can be deferred until the program is ready to process them

A process can send a signal to another process or to itself

The receipt of a signal by a program can be ignored, can be processed according to a default rule, or can cause a function to be called