When we create a kernel thread using kthread_run(), how we can get the tid of the thread, is there something like pthread_self() or gettid() in kernel space?
1 Answer
In kernel-space, you don't need to ask something about thread like in userspace you do by calling gettid() -- you already have access to task_struct of your task:
struct task_struct* tsk = kthread_run(...); pid_t tid = tsk->pid; // Thread id of newly created task (if it was successful) 1 Comment
Farhad
(After a while) i figured it out that if there are several thread
pid_t tid = current->pid will do the job for the running thread.