linux C signal

  • Defined signals
Just a signal flag information, and not to carry large amounts of data, the process will receive a signal from the kernel, and in accordance with the agreed implementation of a code body (response signal), and then continue with the other code, in fact, this way, a signal soft interrupt
Strictly speaking, the process A to the process B can not directly send a signal, but with the core transmission completion signal, the same process B are processed by the kernel of the signals is completed
  • Four Elements signal
  1. Numbering
  2. name
  3. event
  4. The default handling
linux kill -l shows all the signals more commonly 1-31 wherein

Output:

  • Way signal generated
  1. Key generating ctrl + z, ctrl + \, ctrl + s
  2. System call generates kill raise abort
  3. Software condition occurs alarm (timer)
  4. Abnormal production: for example a segmentation fault (illegal memory access), in addition to 0, the memory of their error (bus error)
  5. Generated kill command
  • Signal classification:
  1. Term termination (e.g.: SIGHUP)
  2. Pause Stop
  3. Core generate documentation process dies of reasons (for example: SIGSEGV)
  4. Ign ignore signals
  5. Resumes Cont
  • State of the signal: Hands up (delivery and arrival) or pending (temporarily blocked due to termination)
  • Ignored and allowed to capture the signal SIGKILL SIGSTOP ---- For example, a virus program, you must kill its process. Prior to this, the virus may become the other signals are ignored or catch!
  • PCB contains pending signal set signal and the mask character (a blocking signal sets)
Pending signal set and sets the blocking signals from the organization point of view is a set of signals, we may wish to 1-32 marks each different signal types to press the button ctrl + c, for example, if you press the button will 2 transmission signal, the two signals may undergo changes as follows:

Before execution:

Pending signal set signal 2, state 0 ---- that is, is in a "must" state ---- (double negative equals certainly false pending ---- is already decided)

Press the button:

2 pending signal set signal, a state (but if the blocking signal is identified as a focus signal, the signal pending signal 2 remains focused state 1)

Target process after receiving the signal:

2 pending signal set signal, and becomes 0 transited

This process of change has a very elegant word, called flip

  • Handling signals

 

 

 

  1. Performs the default action
  2. Ignore (discard)
  3. Capture (user handler)

Guess you like

Origin www.cnblogs.com/saintdingspage/p/12165913.html