thread_info结构体定义: structthread_info { unsignedlongflags;/*low level flags*/mm_segment_t addr_limit;/*address limit*/structtask_struct *task;/*main task structure*/intpreempt_count;/*0 => preemptable, <0 => bug*/intcpu;/*cpu*/}; task_struct的结构比较复杂,只列出部分成员变量,完整...
struct thread_info *thread_info: 线程信息。 pid_t pid: 进程ID。 struct task_struct *parent: 指向父进程的指针。 struct list_head children: 子进程链表头部。 struct mm_struct *mm: 进程地址空间描述符。 struct files_struct *files:文件描述符表指针。 进程状态 /* * Task statebitmask. NOTE! The...
进程task_struct中的stack指针指向了进程的thread_union(或者thread_info)的地址, 在早期的内核中这个指针用struct thread_info *thread_info来表示, 但是新的内核中用了一个更浅显的名字void *stack, 即内核栈 即,进程的thread_info存储在进程内核栈的最低端 task_struct中的内核栈stack 我们之前在描述task_struct...
1. task_struct ,thread_info 和内核栈 image.png image.png 在内核中通常current宏获取当前正在运行的task_struct。对于不同的硬件体系current的实现方式不一样,寄存器较多的体系直接用一个寄存器来存储当前进程的task_struct的指针,X86 current把内核栈栈顶指针最后13位(内核栈8KB)清零,计算出thread_info的位置,通...
thread_info结构和内核栈是同时使用的,其实可以理解为thread_info 放在了内核栈的下面,因为栈的增长方向是地址大到地址小,所以两者不冲突。这也间接说明了, 其实内核栈没有union那么大,要被thread_info占据一部分。放在一起还有个好处就是根据esp能够 快速地查找到task_struct的指针,因为thread_info的第一个成员就是...
task_struct数据结构中的stack成员指向thread_union结构(Linux内核通过thread_union联合体来表示进程的内核栈) union thread_union { struct thread_info thread_info; unsigned long stack[THREAD_SIZE/sizeof(long)]; }; 1. 2. 3. 4. struct thread_info是记录部分进程信息的结构体,其中包括了进程上下文信息: ...
但是较新的内核代码中,进程描述符task_struct结构中没有直接指向thread_info结构的指针,而是用一个void指针类型的成员表示,然后通过类型转换来访问thread_info结构。 相关代码在include/linux/sched.h中 代码语言:javascript 复制 #definetask_thread_info(task)((struct thread_info*)(task)->stack) ...
二、task_struct 结构体代码示例 structtask_struct{ #ifdef CONFIG_THREAD_INFO_IN_TASK /* * For reasons of header soup (see current_thread_info()), this * must be the first element of task_struct. */ structthread_infothread_info;
task_struct数据结构中的stack成员指向thread_union结构(Linux内核通过thread_union联合体来表示进程的内核栈) 代码语言:javascript 复制 union thread_union{struct thread_info thread_info;unsigned long stack[THREAD_SIZE/sizeof(long)];}; struct thread_info是记录部分进程信息的结构体,其中包括了进程上下文信息: ...
Linux内核通过一个被称为进程描述符的task_struct结构体来管理进程,这个结构体包含了一个进程所需的所有信息。它定义在include/linux/sched.h文件中。 谈到task_struct结构体,可以说她是linux内核源码中最复杂的一个结构体了,成员之多,占用内存之大。