首页 > 解决方案 > kthread_create() 的参数解释

问题描述

我目前正在阅读 Robert Love 的 Linux 内核开发。在阅读有关线程的内容时,我遇到了 kthread_create() 函数,它接受多个参数并相应地生成一个内核线程。

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

据我所知,第一个参数是指向函数的指针,第二个是 threadfn() 的参数,namefmt 是进程的名称。有人可以解释一下最后这些变量参数是什么吗?

标签: clinuxmultithreadinglinux-kernel

解决方案


kthread_create 参数已在内核源代码中进行了解释。 内核源代码中的 kthreade_create 定义

如您所见,namefmt 是一个 printf 样式的格式字符串。意思是

1. namefmt can be a string literal like "my-kernel-thread" and in that
case    the variable arguments will not be needed. In this case your 
kthread will be named my-kernel-thread

2. namefmt can be a format specifier like "%s-%d" and in that case
variable    arguments can be arguments according to this format
specifier. Like for    this example they can be "my-kernel-thread",
10. In this case your kthread will be named my-kernel-thread-10

推荐阅读