linux内核中的信号机制,linux内核中的信号机制(3)

从上面的分析可以看出,我们看到信号被添加到信号队列之后,会调用signal_wake_up()唤醒这个进程,signal_wake_up()(kernel/signal.c)的定义如下: /* * Tell a process that it has a new active signal.. * * NOT

从上面的分析可以看出,我们看到信号被添加到信号队列之后,会调用signal_wake_up()唤醒这个进程,signal_wake_up()(kernel/signal.c)的定义如下:

/*

* Tell a process that it has a new active signal..

*

* NOTE! we rely on the previous spin_lock to

* lock interrupts for us! We can only be called with

* "siglock" held, and the local interrupt must

* have been disabled when that got acquired!

*

* No need to set need_resched since signal event passing

* goes through ->blocked

*/

void signal_wake_up(struct task_struct *t, int resume)

{

unsigned int mask;

set_tsk_thread_flag(t, TIF_SIGPENDING);//为进程设置TIF_SIGPENDING标志

/*

* For SIGKILL, we want to wake it up in the stopped/traced case.

* We don't check t->state here because there is a race with it

* executing another processor and just now entering stopped state.

* By using wake_up_state, we ensure the process will wake up and

* handle its death signal.

*/

mask = TASK_INTERRUPTIBLE;

if (resume)

mask |= TASK_STOPPED | TASK_TRACED;

if (!wake_up_state(t, mask))

kick_process(t);

}

signal_wake_up()首先为进程设置TIF_SIGPENDING标志,说明该进程有延迟的信号要等待处理。然后再调用 wake_up_state()唤醒目标进程,如果目标进程在其他的CPU上运行,wake_up_state()将返回0,此时调用 kick_process()向该CPU发送一个处理器间中断。当中断返回前戏,会为当前进程处理延迟的信号。

此后当该进程被调度时,在进程返回用户空间前,会调用do_notify_resume()处理该进程的信号。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值