kernel学习之sys_fork,sys_vfork,sys_clone和kernel_thread
发布时间:2016-10-08 19:13:47 所属栏目:Unix 来源:网络整理
导读:用户空间进程创建接口:fork,vfork,clone函数,这里只做简单说明。 fork:使用该系统调用时,子进程复制父进程的全部资源。由于要复制父进程进程描述符给子进
上面进程的创建最终依赖于:do_fork,只是向其传递了不同的参数。 longdo_fork(unsigned long clone_flags, unsigned long stack_start, struct pt_regs *regs, unsigned long stack_size, int __user *parent_tidptr, int __user *child_tidptr) 参数clone_flags非常重要,fork把其设置为SIGCHLD,vfork把其设置为CLONE_VFORK|CLONE_VM|SIGCHLD,clone由用户调用时传递。总的来说,do_fork由clone_flags决定。其值可以自由组合决定。include/linux/sched.h中宏定义: /* *cloning flags: */ #define CSIGNAL 0x000000ff /*signal mask to be sent at exit */ #define CLONE_VM 0x00000100 /* set if VM shared between processes */ #define CLONE_FS 0x00000200 /* set if fs info shared between processes*/ #define CLONE_FILES 0x00000400 /* set if open files shared betweenprocesses */ #define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blockedsignals shared */ #define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue onthe child too */ #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wakeit up on mm_release */ #define CLONE_PARENT 0x00008000 /* set if we want to have the same parent asthe cloner */ #define CLONE_THREAD 0x00010000 /* Same thread group? */ #define CLONE_NEWNS 0x00020000 /* New namespace group? */ #define CLONE_SYSVSEM 0x00040000 /* share system V SEM_UNDO semantics */ #define CLONE_SETTLS 0x00080000 /* create a new TLS for the child */ #define CLONE_PARENT_SETTID 0x00100000 /*set the TID in the parent */ #define CLONE_CHILD_CLEARTID 0x00200000 /*clear the TID in the child */ #define CLONE_DETACHED 0x00400000 /* Unused,ignored */ #define CLONE_UNTRACED 0x00800000 /* set ifthe tracing process can't force CLONE_PTRACE on this clone */ #define CLONE_CHILD_SETTID 0x01000000 /*set the TID in the child */ #define CLONE_STOPPED 0x02000000 /* Start instopped state */ #define CLONE_NEWUTS 0x04000000 /* Newutsname group? */ #define CLONE_NEWIPC 0x08000000 /* Newipcs */ #defineCLONE_NEWUSER 0x10000000 /* New user namespace */ #define CLONE_NEWPID 0x20000000 /* New pidnamespace */ #define CLONE_NEWNET 0x40000000 /* Newnetwork namespace */ #define CLONE_IO 0x80000000 /* Clone io context */ 上面的宏定义都占用了独立的bit,所以能或|组合使用。其低八位没有使用,是为了能和信号量组合使用。 内核线程创建接口: (编辑:佛山站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |