9

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 1

12

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) 
Sign up to request clarification or add additional context in comments.

1 Comment

(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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.