请教两个关于kernel thread的问题。

晨星 2009-12-13 04:31:44
(1)看有的资料上说,kernel thread启动之后将一直运行,直到thread func调用do_exit。那如果thread func没有调用do_exit,而是直接return了会怎样呢?
(2)如果kernel thread的创建者想要监控一下新线程的运行状态,有没有简单的类似user space中的那种wait的机制?
以上问题假定通过kthread_create或kthread_run创建内核线程。
...全文
191 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
晨星 2009-12-13
  • 打赏
  • 举报
回复
谢谢猪头,呵呵。
结帖。
hallowwar 2009-12-13
  • 打赏
  • 举报
回复
如此深奥。
playmud 2009-12-13
  • 打赏
  • 举报
回复
http://www.gnugeneration.com/books/linux/2.6.20/kernel-api/
晨星 2009-12-13
  • 打赏
  • 举报
回复
多谢楼上,能否告知这段文字是来自哪里的?
或者哪里能找到详细一点的内核API的文档?
Wenxy1 2009-12-13
  • 打赏
  • 举报
回复
kthread_create
Inne wersje manuala:

* kthread_create (9freebsd) - The function is used to start daemons such as bufdaemon, pagedaemon, vmdaemon, and the syncer and is intended to be called from The argument is actual...

Name

kthread_create - create a kthread.

Synopsis

struct task_struct * kthread_create(int (*threadfn) (void *data), void * data, const char namefmt[], ...);

Arguments

threadfn
the function to run until signal_pending(current).

data
data ptr for threadfn.

namefmt[]
printf-style name for the thread.

...
variable arguments

Description

This helper function creates and names a kernel thread. The thread will be stopped: use wake_up_process to start it. See also kthread_run, kthread_create_on_cpu.

When woken, the thread will run threadfn() with data as its argument. threadfn() can either call do_exit directly if it is a standalone thread for which noone will call kthread_stop, or return when ´kthread_should_stop´ is true (which means kthread_stop has been called). The return value should be zero or a negative error number; it will be passed to kthread_stop.

Returns a task_struct or ERR_PTR(-ENOMEM).
晨星 2009-12-13
  • 打赏
  • 举报
回复
第一个已经有点明白了,好像是说:如果是个独立的线程(别人不会对它调用kthread_stop),则应该自己调用do_exit退出;否则,应该在别人调用kthread_stop(从而被终止线程将检测到kthread_should_stop())之后通过return将一个0值或者错误码返回给kthread_stop的调用者。
是这样吧?

4,436

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧