How to get kernel thread id?

When we create a kernel thread using kthread_run() , how can we get a thread thread, is there something like pthread_self() or gettid() in the kernel space?

+5
source share
1 answer

In kernel space, you don’t need to ask something about the thread, as in the user space that you call by calling gettid() - you already have access to the task_struct your task:

 struct task_struct* tsk = kthread_run(...); pid_t tid = tsk->pid; // Thread id of newly created task (if it was successful) 
+7
source

All Articles