Linux中task_struct用來控制管理進程,結構以下: struct task_struct { //說明了該進程是否能夠執行,仍是可中斷等信息 volatile long state; //Flage 是進程號,在調用fork()時給出 unsigned long flags; //進程上是否有待處理的信號 int sigpending; //進程地址空間,區份內核進程與普通進程在內存存放的位置不一樣 mm_segment_t addr_limit; //0-0xBFFFFFFF for user-thead //0-0xFFFFFFFF for kernel-thread //調度標誌,表示該進程是否須要從新調度,若非0,則當從內核態返回到用戶態,會發生調度 volatile long need_resched; //鎖深度 int lock_depth; //進程的基本時間片 long nice; //進程的調度策略,有三種,實時進程:SCHED_FIFO,SCHED_RR, 分時進程:SCHED_OTHER unsigned long policy; //進程內存管理信息 struct mm_struct *mm; int processor; //若進程不在任何CPU上運行, cpus_runnable 的值是0,不然是1 這個值在運行隊列被鎖時更新 unsigned long cpus_runnable, cpus_allowed; //指向運行隊列的指針 struct list_head run_list; //進程的睡眠時間 unsigned long sleep_time; //用於將系統中全部的進程連成一個雙向循環鏈表, 其根是init_task struct task_struct *next_task, *prev_task; struct mm_struct *active_mm; struct list_head local_pages; //指向本地頁面 unsigned int allocation_order, nr_local_pages; struct linux_binfmt *binfmt; //進程所運行的可執行文件的格式 int exit_code, exit_signal; int pdeath_signal; //父進程終止是向子進程發送的信號 unsigned long personality; //Linux能夠運行由其餘UNIX操做系統生成的符合iBCS2標準的程序 int did_exec:1; pid_t pid; //進程標識符,用來表明一個進程 pid_t pgrp; //進程組標識,表示進程所屬的進程組 pid_t tty_old_pgrp; //進程控制終端所在的組標識 pid_t session; //進程的會話標識 pid_t tgid; int leader; //表示進程是否爲會話主管 struct task_struct *p_opptr,*p_pptr,*p_cptr,*p_ysptr,*p_osptr; struct list_head thread_group; //線程鏈表 struct task_struct *pidhash_next; //用於將進程鏈入HASH表 struct task_struct **pidhash_pprev; wait_queue_head_t wait_chldexit; //供wait4()使用 struct completion *vfork_done; //供vfork() 使用 unsigned long rt_priority; //實時優先級,用它計算實時進程調度時的weight值 //it_real_value,it_real_incr用於REAL定時器,單位爲jiffies, 系統根據it_real_value //設置定時器的第一個終止時間. 在定時器到期時,向進程發送SIGALRM信號,同時根據 //it_real_incr重置終止時間,it_prof_value,it_prof_incr用於Profile定時器,單位爲jiffies。 //當進程運行時,無論在何種狀態下,每一個tick都使it_prof_value值減一,當減到0時,向進程發送 //信號SIGPROF,並根據it_prof_incr重置時間. //it_virt_value,it_virt_value用於Virtual定時器,單位爲jiffies。當進程運行時,無論在何種 //狀態下,每一個tick都使it_virt_value值減一當減到0時,向進程發送信號SIGVTALRM,根據 //it_virt_incr重置初值。 unsigned long it_real_value, it_prof_value, it_virt_value; unsigned long it_real_incr, it_prof_incr, it_virt_value; struct timer_list real_timer; //指向實時定時器的指針 struct tms times; //記錄進程消耗的時間 unsigned long start_time; //進程建立的時間 //記錄進程在每一個CPU上所消耗的用戶態時間和核心態時間 long per_cpu_utime[NR_CPUS], per_cpu_stime[NR_CPUS]; //內存缺頁和交換信息: //min_flt, maj_flt累計進程的次缺頁數(Copy on Write頁和匿名頁)和主缺頁數(從映射文件或交換 //設備讀入的頁面數); nswap記錄進程累計換出的頁面數,即寫到交換設備上的頁面數。 //cmin_flt, cmaj_flt, cnswap記錄本進程爲祖先的全部子孫進程的累計次缺頁數,主缺頁數和換出頁面數。 //在父進程回收終止的子進程時,父進程會將子進程的這些信息累計到本身結構的這些域中 unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap; int swappable:1; //表示進程的虛擬地址空間是否容許換出 //進程認證信息 //uid,gid爲運行該進程的用戶的用戶標識符和組標識符,一般是進程建立者的uid,gid //euid,egid爲有效uid,gid //fsuid,fsgid爲文件系統uid,gid,這兩個ID號一般與有效uid,gid相等,在檢查對於文件 //系統的訪問權限時使用他們。 //suid,sgid爲備份uid,gid uid_t uid,euid,suid,fsuid; gid_t gid,egid,sgid,fsgid; int ngroups; //記錄進程在多少個用戶組中 gid_t groups[NGROUPS]; //記錄進程所在的組 //進程的權能,分別是有效位集合,繼承位集合,容許位集合 kernel_cap_t cap_effective, cap_inheritable, cap_permitted; int keep_capabilities:1; struct user_struct *user; struct rlimit rlim[RLIM_NLIMITS]; //與進程相關的資源限制信息 unsigned short used_math; //是否使用FPU char comm[16]; //進程正在運行的可執行文件名 //文件系統信息 int link_count, total_link_count; //NULL if no tty 進程所在的控制終端,若是不須要控制終端,則該指針爲空 struct tty_struct *tty; unsigned int locks; //進程間通訊信息 struct sem_undo *semundo; //進程在信號燈上的全部undo操做 struct sem_queue *semsleeping; //當進程由於信號燈操做而掛起時,他在該隊列中記錄等待的操做 //進程的CPU狀態,切換時,要保存到中止進程的task_struct中 struct thread_struct thread; //文件系統信息 struct fs_struct *fs; //打開文件信息 struct files_struct *files; //信號處理函數 spinlock_t sigmask_lock; struct signal_struct *sig; //信號處理函數 sigset_t blocked; //進程當前要阻塞的信號,每一個信號對應一位 struct sigpending pending; //進程上是否有待處理的信號 unsigned long sas_ss_sp; size_t sas_ss_size; int (*notifier)(void *priv); void *notifier_data; sigset_t *notifier_mask; u32 parent_exec_id; u32 self_exec_id; spinlock_t alloc_lock; void *journal_info; };
值得注意:線程是輕量級進程,pcb拷貝自所屬進程,內容同樣,。linux