版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、linux 內(nèi)核源碼分析進(jìn)程管理(一)郭海林2012.9.29linux 內(nèi)核源碼分析進(jìn)程管理(一)重要數(shù)據(jù)結(jié)構(gòu)雙向鏈表(1)結(jié)構(gòu)體定義:struct list_head struct list_head *next, *prev;list_headlist_headlist_headlist_headnextprevnextprevnextprevnextprev重要數(shù)據(jù)結(jié)構(gòu)雙向鏈表(1)結(jié)構(gòu)體定義:list_head重要數(shù)據(jù)結(jié)構(gòu)雙向鏈表(2)為什么要使用這種結(jié)構(gòu)?容器機(jī)制將對象嵌入到另一個對象中怎樣通過鏈表元素找到容器對象的實(shí)例?nextprevtask_structlist_headne
2、xtprevtask_structlist_headnextprevtask_structlist_head重要數(shù)據(jù)結(jié)構(gòu)雙向鏈表(2)為什么要使用這種結(jié)構(gòu)?next重要數(shù)據(jù)結(jié)構(gòu)雙向鏈表(3)./include/linux/list.hlist_entry(p, t, m) 已知類型為t的數(shù)據(jù)結(jié)構(gòu)包含了一個list_head字段,該字段的名字是m,地址為p,返回類型為t的數(shù)據(jù)結(jié)構(gòu)地址list_entry(0 x., struct task_struct, tasks)重要數(shù)據(jù)結(jié)構(gòu)雙向鏈表(3)./include/lin重要數(shù)據(jù)結(jié)構(gòu)散列表(1)結(jié)構(gòu)體定義表頭:struct hlist_head s
3、truct hlist_node *first;節(jié)點(diǎn):struct hlist_node struct hlist_node *next, *pprev;重要數(shù)據(jù)結(jié)構(gòu)散列表(1)結(jié)構(gòu)體定義重要數(shù)據(jù)結(jié)構(gòu)散列表(2)pprevnexthlist_headhlist_nodenullfirstfirstfirsthlist_nodepprevnextpprevnexthlist_nodenull重要數(shù)據(jù)結(jié)構(gòu)散列表(2)pprevnexthlist_h為什么要這么定義?進(jìn)程結(jié)構(gòu)體剖析(1)struct task_struct volatile long state;/* -1 unrunnable,
4、0 runnable, 0 stopped */.long exit_state;/.進(jìn)程的狀態(tài)宏定義:#define TASK_RUNNING0#define TASK_INTERRUPTIBLE1#define TASK_UNINTERRUPTIBLE2#define _TASK_STOPPED4#define _TASK_TRACED8/* in tsk-exit_state */#define EXIT_ZOMBIE16#define EXIT_DEAD32/.為什么要這么定義?進(jìn)程結(jié)構(gòu)體剖析(1)struct task進(jìn)程結(jié)構(gòu)體剖析(2)struct task_struct /.st
5、ruct list_head tasks; /將系統(tǒng)中所有進(jìn)程通過雙向鏈表鏈接起來!/.怎樣訪問所有的進(jìn)程呢?#define for_each_process(p) for (p = &init_task ; (p = next_task(p) != &init_task ; )#define next_task(p) list_entry_rcu(p)-tasks.next, struct task_struct, tasks)給出全局pid號,怎么找到相應(yīng)進(jìn)程的task_struct?進(jìn)程結(jié)構(gòu)體剖析(2)struct task_struct 進(jìn)程結(jié)構(gòu)體剖析(3)struct task_st
6、ruct /.pid_t pid; /進(jìn)程標(biāo)識符(線程)pid_t tgid; /線程組的領(lǐng)頭線程IDstruct task_struct *group_leader; / threadgroup leader/. 系統(tǒng)調(diào)用 getpid() 返回什么?進(jìn)程結(jié)構(gòu)體剖析(3)struct task_struct 進(jìn)程結(jié)構(gòu)體剖析(4.1)struct task_struct /.struct task_struct _rcu *real_parent; /* real parent process */struct task_struct _rcu *parent; /* recipient of
7、 SIGCHLD, wait4() reports */struct list_head children; /* list of my children */struct list_head sibling; /* linkage in my parents children list */.進(jìn)程之間的關(guān)系:父子關(guān)系兄弟關(guān)系進(jìn)程結(jié)構(gòu)體剖析(4.1)struct task_structchildrensiblingchildrensiblingchildrensiblingchildrensiblingchildrensiblingADCBEPNNPPPNNP進(jìn)程結(jié)構(gòu)體剖析(4.2)假設(shè)現(xiàn)在有
8、進(jìn)程A,生成三個子進(jìn)程B、C、D,B進(jìn)程又生成一個子進(jìn)程E。五個task_struct怎么進(jìn)行鏈接?childrensiblingchildrensibling進(jìn)程結(jié)構(gòu)體剖析(5.1)struct task_struct /./* PID/PID hash table linkage. */struct pid_link pidsPIDTYPE_MAX;/.enum pid_typePIDTYPE_PID,PIDTYPE_PGID,PIDTYPE_SID,PIDTYPE_MAX;/進(jìn)程PID/線程組領(lǐng)頭線程PID/會話領(lǐng)頭進(jìn)程ID/類型個數(shù)pids0pids1pids2進(jìn)程結(jié)構(gòu)體剖析(5.1)
9、struct task_struct關(guān)鍵結(jié)構(gòu)體struct upid int nr;struct pid_namespace *ns;struct hlist_node pid_chain;struct pid_link struct hlist_node node; struct pid *pid;struct pid atomic_t count; unsigned int level; struct hlist_head tasksPIDTYPE_MAX; struct rcu_head rcu; struct upid numbers1;countlevertask0task1task
10、2nrnodepidnodepidnspid_chain 關(guān)鍵結(jié)構(gòu)體struct upid struct pid_l213pid命名空間(1)123456781092131lever 0lever 1lever 2213pid命名空間(1)123456781092131lepid命名空間(2)struct nsproxy atomic_t count;struct uts_namespace *uts_ns;struct ipc_namespace *ipc_ns;struct mnt_namespace *mnt_ns;struct pid_namespace *pid_ns;struct
11、net *net_ns;struct pid_namespace /. unsigned int level; struct pid_namespace *parent; /.;pid命名空間(2)struct nsproxy stru結(jié)構(gòu)圖見板書.結(jié)構(gòu)圖見板書.重要函數(shù)(1)根據(jù)進(jìn)程的命名空間ns以及局部PID號nr,怎么找到進(jìn)程的task_struct?nr,ns - upid - pid - task_structstruct pid *find_pid_ns(int nr, struct pid_namespace *ns)struct task_struct *pid_task(struct pid *pid, enum pid_type type)重要函數(shù)(1)根據(jù)進(jìn)程的命名空間ns以及局部PID號nr,怎重要函數(shù)(2)給出task_struct、ID類型、命名空間,怎么取得命名空間局部的ID號?task_struct - pid - upid - nrstruct pid *task_pid(struct task_struct *task)pid_t pid_nr_ns(struct pi
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030融資租賃行業(yè)融資租賃創(chuàng)新金融租賃市場競爭市場研討
- 涵洞及排水溝施工方案
- 盾構(gòu)測量專項(xiàng)方案
- 2026年廢廢核污染波污染波污染易發(fā)區(qū)保護(hù)保險合同中
- 2022年南充職業(yè)技術(shù)學(xué)院單招面試題庫及答案解析
- 嘉峪關(guān)2022事業(yè)單位招聘考試真題及答案解析卷5
- 中秋主題作文八篇
- 2026年初級音樂教師專業(yè)能力筆試模擬題
- 2026年?duì)I養(yǎng)師食品營養(yǎng)學(xué)與健康飲食指導(dǎo)題庫
- 2026年企業(yè)網(wǎng)絡(luò)安全與數(shù)字化轉(zhuǎn)型考試題庫
- 建筑工程檢測設(shè)備配置清單及要求
- CAE入門資料:有限元分析
- 加工中心操作工初級工考試試卷與答案
- 新生兒圍生期感染護(hù)理查房
- 內(nèi)蒙古呼和浩特市2025-2026學(xué)年高三上學(xué)期第一次質(zhì)量監(jiān)測 化學(xué)試卷
- 丈夫出軌婚內(nèi)協(xié)議書范本
- 厚型防火涂料施工規(guī)范及操作流程
- 婚姻家庭矛盾糾紛調(diào)解
- 中性粒細(xì)胞缺乏癥診療與管理體系
- 醫(yī)院行政管理體系介紹
- (新版)液氯安全標(biāo)簽
評論
0/150
提交評論