Outline 进程描速精 进程的等待和唤醒 进程切换 进程的创建和刚确 进程调应 小结和作业 4口t4四1是142刀00 陈香兰(xlanchenoustc,ed加,cn)(计异款应Linux操作系统分折Chapter 9洗任管理。 Decenber23,201423/95
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Outline . 1. 进程描述符 .2 进程的等待和唤醒 .3 进程切换 4. 进程的创建和删除 5. 进程调度 .6 小结和作业 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9 进程管理 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) December 23, 2014 23 / 95
进程等待 。等待一个特定事件的进程能调用下面几个函数中的任一个 sleep_on sleep on timeout interruptible sleep_on interruptible_sleep_on_timeout ·进程等待由需要等待的进程自己进行(调用) 4口卡4是14P,刀00 陈香兰(xlanchenoustc,ed加,cn)(升异教应Linux操作系统分折Chapter 9连任管理 Decenber23,201424/95
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 进程等待 等待一个特定事件的进程能调用下面几个函数中的任一个 ▶ sleep_on ▶ sleep_on_timeout ▶ interruptible_sleep_on ▶ interruptible_sleep_on_timeout 进程等待由需要等待的进程自己进行(调用) 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9 进程管理 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) December 23, 2014 24 / 95
进程等待 o sleep_on s1 eep on相当于 void sleep_on(wait_queue_head_t *wq) wait_queue_t wait: init_waitqueue_entry(&wait.current); current->state TASK_UNINTERRUPTIBLE: add_wait_queue(wq,&wait);/wq points to the wait queue head schedule(); remove_wait_queue(wq.&wait): ~实际的s1eep_on系列代码,参见kernel/sched.c 4口4四1是42刀00 陈香兰(xlanchenoustc,ed加,cn)(计异款应Linux操作系统分折Chapter 9注任管理。 Decenber 23.2014 24 /95
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 进程等待 sleep_on . sleep_on相当于 . . void sleep_on(wait_queue_head_t *wq) { wait_queue_t wait; init_waitqueue_entry(&wait, current); current->state = TASK_UNINTERRUPTIBLE; add_wait_queue(wq, &wait); /* wq points to the wait queue head */ schedule(); remove_wait_queue(wq, &wait); } ▶ 实际的sleep_on系列代码,参见kernel/sched.c 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9 进程管理 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) December 23, 2014 24 / 95
进程等待 ●此外,还可能按照如下方式进行sleep 条件等待 DEFINE_WAIT(wait): prepare_to_wait_execlusive(&wq,&wait,TASK_INTERRUPTIBLE): /◆wq is the head of the wait queue◆/ if(!condition) schedule(); finish_wait(&wq,&wait); 4口4四1是42刀00 陈香兰(xlanchenoustc,ed加,cn)(计异款应Linux操作系统分折Chapter 9洗任管理。 Decenber 23.2014 24 /95
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 进程等待 此外,还可能按照如下方式进行sleep . 条件等待 . . DEFINE_WAIT(wait); prepare_to_wait_execlusive(&wq, &wait, TASK_INTERRUPTIBLE); /* wq is the head of the wait queue */ ... if (!condition) schedule(); finish_wait(&wq, &wait); 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9 进程管理 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) December 23, 2014 24 / 95
进程等待 o例如事件等待wait_event_wait_event wait_event,参见include/1inux/wait.h #define_wait_event(wq.condition)\ do DEFINE_WAIT(_wait);\ for(:;){\ prepare_to_wait(&wq,&_wait,TASK_UNINTERRUPTIBLE):\ if (condition)\ break;\ schedule();\ H finish_wait(&wq.&_wait);\ while (0) 等待,直到事件发生(有效,或…) 4口4四1是4P刀00 陈香兰(x1 anchenoustc,ed加.cn)(升异丸应Lnux掉作系统分折Chapter 0注在管理 Decenber 23.2014 24 /95
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 进程等待 例如事件等待wait_event−→__wait_event . __wait_event, 参见include/linux/wait.h . . #define __wait_event(wq, condition) \ do { \ DEFINE_WAIT(__wait); \ \ for (;;) { \ prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \ if (condition) \ break; \ schedule(); \ } \ finish_wait(&wq, &__wait); \ } while (0) ▶ 等待,直到事件发生(有效,或…) 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室 Linux操作系统分析Chapter 9 进程管理 @计算机学院嵌入式系统实验室@苏州研究院中国科学技术大学Fall 2014) December 23, 2014 24 / 95