Linux kernel Process Management ~Supplement(updating)
来源:互联网 发布:阿里云服务器开启ftp 编辑:程序博客网 时间:2024/06/11 20:50
Author: Harold Wang
http://blog.csdn.net/hero7935
1.Task state:
struct task_struct* task;
/*
* This is OK even in SMP system, because it can involve Memory Barrier if necessary.
*/
set_task_state(task,state);
set_task_state(current,state)=set_current_state(state)
/*
* We can simply use this instead if not in SMP environment;
*/
task->state=state;
2.Iterate all processes:
struct task_struct* task;
for_each_process(task)
{
printk("%s[%d]/n",task->comm,task->pid);
}
// if we want get the Init process(PID=1)
for(task=current;task!=init_task;task=task->parent);
//The relationship between process family:
3. Process Creation:
Modern Unix kernels involve three mechnisms to create process with less overhead, at least, do their best.
- Copy On Write Tech
- Lightweight process
- vfork() system call(deprecated, see Advanced Unix Programming 2rd edition)
IN LINUX:
fork() :
--copy all the resources the parent has-->generate process
--clone(SIGCHLD,0)
vfork():
--copy works as fork() except the task_struct and kernel stack-->generate thread.
--clone(CLONE_VFORK|CLONE-VM|SIGCHLD,0)
NOTE: we can specify the resources that we want the "clone" to share with its parent.
like : CLONE_FS CLONE_FILES CLONE_VM CLONE_SIGHAND et al.
//In fact, fork/vfork/clone, they all call do_fork at last to achieve their goals.
Author: Harold Wang
http://blog.csdn.net/hero7935
//if this is still not clear, please look at this picture to see if any better:
4. Process Switch see x86 or amd64
5. Process Termination:
two methods to teminate process---->
exit_group():corresponding main kernel function is do_group_exit()
_exit():corresponding main kernel function is do_exit()
note: do_exit() only mean that the thread is in the state of EXIT_ZOMBIE, when all objects associated with the task are freed, the task is not runnable(no longer has an address space in which to run) . The only memory it occupies is its kernel stack, the thread_info structure,and the task_struct structure. YES, the final work will be fixed by its parent who call the wait() function. YES, may be his original parent has left him, so forget_orginal_parent() will give a hand. YES, it nobody like this orphan, init thread will do.
Author: Harold Wang
http://blog.csdn.net/hero7935
when we can do_exit
- Linux kernel Process Management ~Supplement(updating)
- Linux kernel Process Management 3.1(overview)——Schedule System
- Linux Process Management
- Process management in Linux
- linux process management
- Linux kernel management style
- linux kernel time management
- Linux kernel Process Management 2.1(amd64)——Creation and Switch
- Linux kernel Process Management 2.2(x86)——Creation and Switch
- linux kernel startup process!
- Linux kernel boot process
- Linux kernel Process Management 1——Conparison and Contrast between linux 2.4 VS linux 2.6 in process kernel stack layout
- Linux Kernel Memory Management (1)
- Linux Kernel Memory Management (2)
- Linux kernel memory management (ARM)
- 【Linux】Linux Kernel--Memory Management(一)
- 【Linux】Linux Kernel--Memory Management(二)
- Understand the linux kernel-ch3-Process descriptor
- AnyCut | 创建桌面快捷方式 | PackageManager获得系统基本信息 | UserTask多线程
- SVN的安装
- MyEclipse for Linux版下载
- 清洗
- 【jQuery 教程】jQuery 事件
- Linux kernel Process Management ~Supplement(updating)
- MySql 建表、添加字段、修改字段写法
- FreeMarker使用小记(HelloWorld)
- linux 2.6内核 编译模块Makefile 详解
- 如何修改SQL Server 2005服务器名称(转)
- 关于手机定位返回null
- cd3wd – 2012 之后,世界重建教程(转)
- 路由选择协议知识汇总
- Oracle学习小笔记