[Linux Internals] My notes on: Signals, Interrupts, Exceptions, Traps.,etc

  • Signal can be sent at any time to a process and if its sent when process is not executing, it must be saved by kernel until process resumes execution.
    Signals generated, but not yet delivered are — “Pending signals”. At any time, ONLY ONE type of pending signal can exist for a process; any additional same type of pending signals are DISCARDED!.
Credit: Google images
  • Signals can be sent between processes or between the kernel and a process
  • 3 possible ways a process can respond: explicitly ignore the signal, execute the default action or catch the signal by invoking corresponding signal-handler function.
  • How to list all the signals available in a specific OS: “kill -l”
  • No actual data is being sent as part of signal; Its just a notification that an event has occurred
  • Signals can be handled either by default handlers or user-processes can define their own handlers to handle them. There are exceptions : The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
    SIGKILL 9 Term Kill signal
    SIGSTOP 17,19,23 Term
    suspends the process until you do a SIGCONT
  • Please note that SIGSTOP and SIGTSTP are 2 different signals!
#define SIGSTOP     19  /* Stop, unblockable (POSIX).  */
#define SIGTSTP 20 /* Keyboard stop (POSIX). Ctrl+Z */
List of signals used very often
  • Signals delivery mechanism can be either synchronous or asynchronous
  • trap command allows us to trap some or all of these signals, and perform operations on the trapped signals.
trap [options] [argument] [Signal specification]
System calls involved
  • SIGINT is intended as a signal sent by the user
  • In general the processes communicate with each other using other signals. For ex: a parent process usually sends SIGTERM to its children to terminate them, even if SIGINT has the same effect.
  • SIGQUIT generates a core dump which is useful for debugging.

Interrupts vs Signals :

  • Interrupts are initiated by CPU (SIGFPE, SIGSEGV, page fault) or CPU instructions(traps) or hardware devices (keyboard, mouse)
  • CPU will then interrupt the current task and notify the kernel about the interrupt
  • Hardware Interrupt: directly handled by Interrupt Handler
  • Software Interrupt: kernel sends signal to the process; Signals may NOT be sent always sent in response to a software interrupt
  • SIGCHLD signal is sent to a parent process when its child process terminates
  • SIGINT is sent when either software interrupt occurs or by a external process

So, in nutshell, how all they look like ?

Image Source: Wikipedia
  1. Determine the cause of the exception/interrupt.
  2. Handle the exception/interrupt.
  1. Select a process to restore and resume.
  2. Restore the context of the selected process.
  3. Resume execution of the selected process.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
svalak

svalak

Passionate about learning ; Will write about #systemdesign #DSA #algorithms #linuxinternals #technology; Painting/Poem writing are my hobbies; Voracious Reader