Reputation: 19
I write a program name test.c. In this program, I created three thread by pthead_create. These thread named thread0, thread1, thread2 by prctl(PR_SET_NAME, name). The thread function code as follows:
void *output(void *arg) {
char *x = (char *) arg;
char name[40] = "thread";
strcat(name, x);
prctl(PR_SET_NAME, name);
while(1){
printf("%s\n", name);
sleep(10000);
};
}
Then I write a kernel module print.c which function is to print the each task_struct infomation int kernel process list. the code as follows:
struct task_struct *task = &init_task;
do{
printk("%s\n", task->comm);
}while((task=next_task(task)) != &init_task);
I run the program test.c first correctly and then insmod the module print.ko correctly. Unexpectly, I didn't find three threads' information. So, I want to ask that the thread created by pthread_create would not appear on kernel process list. is this opinion correct or not?
Upvotes: 0
Views: 127
Reputation: 229304
A thread is also represented by a struct task
in the kernel. You can iterate through each thread in a task by using e.g. the while_each_thread macro:
struct task_struct *task = ...;
struct task_struct *t = task;
do {
//use t
} while_each_thread(task, t);
Note: I don't know the proper locking, if any, around the task structs you need to be able to iterate through them like this.
Upvotes: 0