Linux102系列会详细讲解Linux0.11版本中的102个文件,本文讲解linux0.11的第15个文件
include/linux/sched.h中的进程PCB结构体——task_struct的源码。
为什么一个结构体单独出一篇文章?因为PCB太重要了! 我们说的进程的一切抽象全部在这里面,所以要好好看!
一、源码全貌
1.task_struct的主要作用
task_struct结构体是进程抽象概念的代码化具象化 ,理解这些数据结构是理解进程调度机制的关键,也是理解内核的关键。
2.源码完整版
struct task_struct {
/* these are hardcoded - don't touch */
long state; /* -1 unrunnable, 0 runnable, >0 stopped */
long counter;
long priority;
long signal;
struct sigaction sigaction[32];
long blocked; /* bitmap of masked signals */
/* various fields */
int exit_code;
unsigned long start_code,end_code,end_data,brk,start_stack;
long pid,father,pgrp,session,leader;
unsigned short uid,euid,suid;
unsigned short gid,egid,sgid;
long alarm;
long utime,stime,cutime,cstime,start_time;
unsigned short used_math;
/* file system info */
int tty; /* -1 if no tty, so it must be signed */
unsigned short umask;
struct m_inode * pwd;
struct m_inode * root;
struct m_inode * executable;
unsigned long close_on_exec;
struct file * filp[NR_OPEN];
/* ldt for this task 0 - zero 1 - cs 2 - ds&ss */
struct desc_struct ldt[3];
/* tss for this task */
struct tss_struct tss;
};
task_struct结构体中,包含了i387_struct和tss_struct两个结构体,具体如下:
①i387协处理器结构体
struct i387_struct {
long cwd;
long swd;
long twd;
long fip;
long fcs;
long foo;
long fos;
long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */
};
②任务切换时CPU快照(上下文信息)
struct tss_struct {
long back_link; /* 16 high bits zero */
long esp0;
long ss0; /* 16 high bits zero */
long esp1;
long ss1; /* 16 high bits zero */
long esp2;
long ss2; /* 16 high bits zero */
long cr3;
long eip;
long eflags;
long eax,ecx,edx,ebx;
long esp

最低0.47元/天 解锁文章
1057

被折叠的 条评论
为什么被折叠?



