UTLK Signal 笔记

1. Signals sent to a process that is not currently executing must be saved by the kernel until that process resumes execution. 


2. 信号的两个概念:

内核或者一个进程向另一个进程发送信号( send a signal to),包括两个过程:

Signal generation

The kernel updates a data structure of the destination process to represent that a new signal has been sent.

         !!终于在 11.2 找到了一个信号如何令一个阻塞的系统调用中断并返回的,即把“调用该阻塞的系统调用的”进程  从TASK_INTERRUPTIBLE状态唤醒:
1. Many kernel functions generate signals: they accomplish the first phase of signal handling ( 注:signal generation ) described earlier in the section "The Role of Signals" by updating one or more process descriptors as needed. 
         2. specific_send_sig_info() -->signal_wake_up() --> try_to_wake_up()
         All functions in Table 11-9 end up invoking the specific_send_sig_info( ) function described in the next                  section.
Invokes try_to_wake_up( )see the section "The try_to_wake_up( ) Function" inChapter 7to awake the process if it is either in TASK_INTERRUPTIBLE state , or inTASK_STOPPED state and the signal isSIGKILL.

Signal delivery

The kernel forces the destination process to react to the signalby changing its execution state,(有可能唤醒睡眠中的进程) by starting the execution of a specified signal handler, or both.


3. 信号挂起(pending)的概念

Signals that have been generated but not yet delivered are called pending signals

At any time, only one pending signal of a given type may exist for a process; additional pending signals of the same type to the same process are not queued but simply discarded.(信号不排队) Real-time signals are different, though: there can be several pending signals of the same type.


信号挂起的几个因素:

  • Signals are usually delivered only to the currently running process (that is, to thecurrent process).

  • Signals of a given type may be selectively blocked by a process (see the later section "Modifying the Set of Blocked Signals"). In this case, the process does not receive the signal until it removes the block.
    相关API:sigprocmask()通过使用信号阻塞字来阻塞信号的投递,sigpending()可以获取已经产生,当前正阻塞着的信号;)

  • When a process executes a signal-handler function, it usually masks the corresponding signal.e., it automatically blocks the signal until the handler terminates. A signal handler therefore cannot be interrupted by another occurrence of the handled signal, and the function doesn't need to be reentrant.


4. 信号阻塞和被忽略的区别:

sigprocmask()设置阻塞的信号,如果信号这些阻塞的信号产生,那么它们是挂起的,用sigpending()可以查看这些挂起的信号;

Notice that blocking a signal is different from ignoring it. A signal is not delivered as long as it is blocked; it is delivered only after it has been unblocked. An ignored signal is always delivered, and there is no further action.


5. SIGKILL/SIGSTOP

The SIGKILL and SIGSTOP signals cannot be ignored, caught(设置信号处理函数), or blocked, and their default actions must always be executed. Therefore,SIGKILL and SIGSTOP allow a user with appropriate privileges to terminate and to stop, respectively, every process,[*] regardless of the defenses taken by the program it is executing.


6. Fata Signal

A signal is fatal for a given process if delivering the signal causes the kernel to kill the process. TheSIGKILL signal is always fatal.

POSIX Requirement:If a fatal signal is sent to a multithreaded application, the kernel will kill all threads of the applicationnot just the thread to which the signal has been delivered.


7. Thread Group

In this chapter the term "thread group" denotes any thread group, even if it is composed by a single (conventional) process. For instance, when we state thatkill( ) can send a signal to a thread group, we imply that this system call can send a signal to a conventional process, too. We will use the term "process" to denote either a conventional process or a lightweight process that is, a specific member of a thread group.


7. 内核信号相关数据结构

内核需要这些数据结构来处理的任务:

For each process in the system, the kernel must keep track of what signals are currently pending or masked; the kernel must also keep track of how every thread group is supposed to handle every signal.


task_struct 中和内核相关的字段如下:


Type

Name

Description

struct signal_struct *

signal

Pointer to the process's signal descriptor

struct sighand_struct *

sighand

Pointer to the process's signal handler descriptor

sigset_t(每一位表示一个信号)

blocked

Mask of blocked signals

sigset_t

real_blocked

Temporary mask of blocked signals (used by the rt_sigtimedwait( ) system call)

struct sigpending

pending

Data structure storing the private pending signals

unsigned long

sas_ss_sp

Address of alternative signal handler stack

size_t

sas_ss_size

Size of alternative signal handler stack

int (*) (void *)

notifier

Pointer to a function used by a device driver to block some signals of the process

void *

notifier_data

Pointer to data that might be used by the notifier function (previous field of table)

sigset_t *

notifier_mask

Bit mask of signals blocked by a device driver through a notifier function


8. 


参考:Understanding The Linux Kernel, 3rd, Chapter 11

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值