Aman Sharma
Aman Sharma

Reputation: 23

Explanation of arguments to kthread_create()

I am currently reading Linux kernel development By Robert Love. When reading about threads, I came across kthread_create() function which takes several arguments and spawns a kernel thread accordingly.

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

As far as I know, the first argument is the pointer to the function, second one is the argument to the threadfn(), namefmt is the name of the process. Can someone please explain what are those variable arguments are at the end?

Upvotes: 0

Views: 2843

Answers (1)

Imran Khan
Imran Khan

Reputation: 36

kthread_create arguments have been explained in kernel source code. kthreade_create definition in kernel source

As you can see namefmt is a printf-style format string. Which means

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

Upvotes: 2

Related Questions