Process - SIGNAL (KILL, ...)

> Operating System - Kernel (Windows, Unix, Linux) > OS - Process (Task)

1 - About

Signals are an OS (Linux) inter-process communication mechanism.

They are used to signal asynchronous events to one or more processes.

A signal could be generated:

  • by a keyboard interrupt
  • by an error condition.
  • as job control commands to child processes
Type Mean of Communication between
Interrupts the CPU and the OS kernel
Signals the OS kernel and OS processes

Signals may be initiated by:

  • the OS kernel (e.g: SIGFPE, SIGSEGV, SIGIO),
  • or by a process(kill()).

They are eventually managed by the OS kernel, which delivers them to the target thread/process, invoking either:

  • a generic action (ignore, terminate, terminate and dump core)
  • or a process-provided signal handler.

Hardware interrupts can generate signals, like a keyboard interrupt generates SIGINT. Thus interrupts and signals are closely tied to each other.

Number Name Description
11 SIGSEGV segmentation fault
SIGINT (generated, for example, by typing your interrupt character, typically control-C)
SIGTERM (generated with the kill command
SIGINFO ask for info (generated, for example, by typing the status character, typically control-T, although on some platforms, such as Mac OS X, the status character is not set by default, so you must set it with stty(1) in order to use it)
SIGUSR1 a little bit the same meaning than SIGINFO
Advertising

3 - Management

3.1 - List

kill -l

3.2 - Example

# Handle shutdowns
function gracefulshutdown {
  shutdown.sh
}
 
trap gracefulshutdown SIGINT
trap gracefulshutdown SIGTERM
trap gracefulshutdown SIGKILL

3.3 - Trap

See trap

Example: calling the exit function, the following finish function will run.

#!/bin/bash
function finish {
  # Your cleanup code here
}
trap finish EXIT

4 - Documentation / Reference

os/process/signal.txt · Last modified: 2019/03/12 14:20 by gerardnico