notes

Personal notes
git clone git://git.laack.co/notes.git
Log | Files | Refs

Signal.md (2073B)


      1 # Signal
      2 
      3 **Source:** CS 6200
      4 
      5 **Chapter:** P2L4
      6 
      7 **Definition:** A signal is an event triggered by a process or a CPU. Signals are dictated by the OS.
      8 
      9 Signals can be masked on the basis of a given process to disable / suspend the signal's notification. This can be useful in specific contexts to solve potential deadlock situations where the handler would try to acquire a mutex that has been locked but not yet unlocked by the current thread. Signals that arrive while masked are set as pending and will result in the handler being invoked once they are unmasked.
     10 
     11 This masking is done by a string of bits, one bit per signal (0 is masked, 1 is unmasked).
     12 
     13 ## Signal Types
     14 
     15 ### (Standard) One-Shot Signals
     16 
     17 In the case of one-shot signals, sending multiple signals of this type while being masked will result in only one invocation of the appropriate handler once they are unmasked
     18 
     19 ### Real-Time Signals
     20 
     21 In the case of real time signals, sending multiple signals of this type while being masked will result in an equal number of invocations of the appropriate handler once they are unmasked.
     22 
     23 ## Signal Handling
     24 
     25 If a process tries to access illegal memory, it will be sent the sigsegv signal from the OS. The OS maintains the signal handler table for each process, so once this signal is sent, it will lookup the handler's memory address and set the PC to that address for execution.
     26 
     27 The OS specifies some default actions for different signals. Some defaults could be termination / ignoring the signal.
     28 
     29 For most, but not all, signals a process can define its own signal handlers.
     30 
     31 ## Deadlock Resolution
     32 
     33 Mentioned above, signals (and interrupts) can result in deadlocks when their handlers require a mutex that has already been locked by the thread it is executing on. This can be resolved by masking the signal in the critical section, or by not using the same mutexes in threads and handlers, but another way, implemented by SunOS, is to allow signals / interrupts to become their own threads when they are executing blocking operations (dynamic determination).