Linux内核中的信号机制——信号发送

发表于:2013-2-16 10:23

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:ce123    来源:51Testing软件测试网采编

分享:

  从上面的分析可以看出,我们看到信号被添加到信号队列之后,会调用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()处理该进程的信号。

相关链接:

Linux内核中的信号机制——一个简单的例子

44/4<1234
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号