上一篇中提到了task_struct,這篇就針對task_struct做一簡單的概括:
task_struct是Linux內核的⼀一種數據結構,它會被裝載到RAM⾥裏並且包含着進程的信息。 每個進程都把它的信息放在task_struct 這個數據結構⾥裏,task_struct 包含了這些內容:
標示符 : 描述本進程的唯⼀一標⽰示符,⽤用來區別其他進程。
狀態 :任務狀態,退出代碼,退出信號等。
優先級 :相對於其他進程的優先級。
程序計數器:程序中即將被執⾏行的下⼀一條指令的地址。
內存指針:包括程序代碼和進程相關數據的指針,還有和其他進程共享的內存塊的指針
上下文數據:進程執⾏行時處理器的寄存器中的數據。
I/O狀態信息:包括顯⽰示的I/O請求,分配給進程的I/O設備和被進程使⽤用的⽂文件列表。
記賬信息:可能包括處理器時間總和,使⽤用的時鐘數總和,時間限制,記賬號等。
struct task_struct{
volatile long state;//說明了該進程是否可以執行還是可以中斷等待等
void *stack;
atomic_t usage;
unsigned int flags;//flags是進程號,在調用fork()的時候給出
unsigned int ptrace;
int lock_depth;//鎖深度
#ifdef CONFIG_SMP
#ifdef __ARCH_WANT_UNLOCKED_CTXSW
int oncpu;
#endif
#endif
int prio,static_prio,normal_prio;
unsigned int rt_priority;</span>
const struct sched_class *sched_class;
struct sched_entity se;
struct sched_rt_entity rt;
#ifdef CONFIG_PREEMPT_NOTIFIERS
struct hlist_head preempt_notifiers;
unsigned char fpu_counter;
#ifdef CONFIG_BLK_DEV_IO_TRACE
unsigned intbtrace_seq;
#endif
unsigned int policy;
cpumask_t cpus_allowed;
#ifdef CONFIG_TREE_PREEMPT_RCU
int rcu_red_lock_nesting;
char rcu_red_unlock_special;
struct rcu_node *rcu_blocked_node;
struct list_head rcu_node_entry;
#endif
#if defined(CONFIG_SCHEDSTATS)||defined(CONFIG_TASK_DELAY_ACCT)
struct sched_info sched_info;
#endif
這是從庫中的task_struct的截圖:
(ps:如果想詳細瞭解:可以在自己系統下通過這個目錄下更詳細的瞭解)