【发布时间】: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