当我们使用创建内核线程时kthread_run()
,我们如何获得线程的tid,是否有类似pthread_self()
或gettid()
内核空间?
在内核空间中,您不需要通过调用来询问有关用户空间中的线程的信息gettid()
- 您已经可以访问task_struct
任务:
struct task_struct* tsk = kthread_run(...);
pid_t tid = tsk->pid; // Thread id of newly created task (if it was successful)
Run Code Online (Sandbox Code Playgroud)