【问题标题】:Blocked system call doesn't let SIGKILL kill the process阻塞的系统调用不会让 SIGKILL 杀死进程
【发布时间】:2013-04-26 05:47:21
【问题描述】:

我对内核线程之间的信号传播有疑问。 场景是这样的:

从用户空间应用程序进行系统调用,内核在系统调用中创建一个线程(我们将其命名为 thread1)。

现在在 thread1 内部,内核在一个 while 循环中循环,它被阻塞了。主线程也在一个while循环中循环。 如果我执行“kill -9 ”,应用程序将无法正常退出。甚至 /proc 条目仍然存在。 虽然 /proc//fd 文件夹变空了。

如果我在主线程的 while 循环中添加以下内容,它会正确捕获信号并退出。如果我只在thread1的while循环中加入following,主线程仍然没有退出。

if (signal_pending(current)) {
  return;
}

您能否建议,在这种 kill -9 信号的情况下内核应该如何表现?在 SIGKILL 之后,进程的状态变为 Zombie。

系统调用有如下实现:

thread1 = kthread_create(thread_fn, NULL, "thread1");
if (thread1) {
    wake_up_process(thread1);
}
printk(KERN_NOTICE "Main thread: current:%s\n", current->comm);
while(1) {
    DELAY_SEC(1)

thread_fn 是:

int thread_fn(void* data)
{
    while(1) {
        DELAY_SEC(1)
   }
}

问候,

索尼卡

【问题讨论】:

  • 你如何创建进程,它仍然是僵尸?

标签: c linux kernel block system-calls


【解决方案1】:

向进程发送信号只是为该信号设置一个相应的标志。

当一个进程从内核模式返回时(例如,当一个系统调用返回时),这些标志被检查。如果之前设置了其中一个,则执行相应的操作。

由于您的系统调用永远不会返回,因此这永远不会发生。

换句话说:你不能真正杀死 Linux 进程。你可以礼貌地让它死。

【讨论】:

    猜你喜欢
    • 2012-01-31
    • 2015-05-12
    • 1970-01-01
    • 2017-10-03
    • 2014-03-19
    • 2014-07-15
    • 1970-01-01
    • 1970-01-01
    • 2013-06-30
    相关资源
    最近更新 更多