1 / 8

进程的创建和删除 based on Linux3.2

进程的创建和删除 based on Linux3.2. 孟宁 电话:0512-68839302 腾讯微博:@mengning997 新浪微博:@孟宁V5 E-mail:mengning@ustc.edu.cn 主页:http://staff.ustc.edu.cn/~mengning 地址:苏州工业园区独墅湖高等教育区仁爱路166号明德楼A302室. 20 1 2 年 3 月. 0号进程与1号进程. start_kernel 0 - mm_init_owner(&init_mm, &init_task); rest_init

Download Presentation

进程的创建和删除 based on Linux3.2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 进程的创建和删除based on Linux3.2 孟宁 电话:0512-68839302腾讯微博:@mengning997 新浪微博:@孟宁V5 E-mail:mengning@ustc.edu.cn 主页:http://staff.ustc.edu.cn/~mengning 地址:苏州工业园区独墅湖高等教育区仁爱路166号明德楼A302室 2012年3月

  2. 0号进程与1号进程 • start_kernel • 0- mm_init_owner(&init_mm, &init_task); • rest_init • 1- kernel_thread(kernel_init • init_post • run_init_process("init");调用kernel_execve变成用户态进程 • 2- kernel_thread(kthreadd • schedule(); • cpu_idle();

  3. init进程 • 在系统启动阶段,操作系统内核部分初始化阶段的结尾,依据/etc/inittab配置文件来对系统进行用户态的初始化。 • 在系统运行当中root用户可以运行init命令把系统切换到不同运行级别(run level) • 在系统起来以后,init作为一个daemon进程运行

  4. 进程的创建 • 新的进程通过复制旧进程(即父进场)而建立,fork,vfork和clone。 • 在物理内存中为新进程创建一个task_struct结构 • 复制旧进程的task_struct结构并修改部分内容 • 为新进程分配新的内核堆栈和进程标识符 • 新进程task_struct结构插入进程链关系(包括运行队列) • 新进程即可被调度选择执行

  5. do_fork • copy_process • dup_task_struct • alloc_task_struct_node • alloc_thread_info_node • alloc_pid • INIT_LIST_HEAD(&p->thread_group); • wake_up_new_task

  6. 撤销进程 • 进程终止的一般方式是exit()系统调用 • 这个系统调用可能由编程者明确的在代码中插入 • 另外,在控制流到达主过程[C中的main()函数]的最后一条语句时,执行exit()系统调用 • 内核可以强迫进程终止 • 当进程接收到一个不能处理或忽视的信号时 • 当在内核态产生一个不可恢复的CPU异常而内核此时正代表该进程在运行

  7. do_exit • /* causes final put_task_struct in finish_task_switch(). */ • tsk->state = TASK_DEAD; • schedule();/__schedule • context_switch • finish_task_switch • put_task_struct/__put_task_struct • free_task

  8. 不论你多么富有,多么有权势,当生命结束之时,所有的一切都只能留在世界上,唯有灵魂跟着你走下一段旅程。人生不是一场物质的盛宴,而是一次灵魂的修炼,使它在谢幕之时比开幕之初更为高尚。——稻盛和夫不论你多么富有,多么有权势,当生命结束之时,所有的一切都只能留在世界上,唯有灵魂跟着你走下一段旅程。人生不是一场物质的盛宴,而是一次灵魂的修炼,使它在谢幕之时比开幕之初更为高尚。——稻盛和夫 谢谢大家! 参考资料: 《深入理解Linux内核》第三版 http://www.linuxfromscratch.org http://savannah.nongnu.org/projects/sysvinit

More Related