博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
进程fork处理
阅读量:4153 次
发布时间:2019-05-25

本文共 2260 字,大约阅读时间需要 7 分钟。

进程或者线程创建do_fork
 
/* For compatibility with architectures that call do_fork directly rather than * using the syscall entry points below. */long do_fork(unsigned long clone_flags,       unsigned long stack_start,       unsigned long stack_size,       int __user *parent_tidptr,       int __user *child_tidptr){ return _do_fork(clone_flags, stack_start, stack_size,   parent_tidptr, child_tidptr, 0);}
/* *  Ok, this is the main fork-routine. * * It copies the process, and if successful kick-starts * it and waits for it to finish using the VM if required. */long _do_fork(unsigned long clone_flags,       unsigned long stack_start,       unsigned long stack_size,       int __user *parent_tidptr,       int __user *child_tidptr,       unsigned long tls){ struct task_struct *p; int trace = 0; long nr;  /*  * Determine whether and which event to report to ptracer.  When  * called from kernel_thread or CLONE_UNTRACED is explicitly  * requested, no event is reported; otherwise, report if the event  * for the type of forking is enabled.  */ if (!(clone_flags & CLONE_UNTRACED)) {  if (clone_flags & CLONE_VFORK)   trace = PTRACE_EVENT_VFORK;  else if ((clone_flags & CSIGNAL) != SIGCHLD)   trace = PTRACE_EVENT_CLONE;  else   trace = PTRACE_EVENT_FORK;   if (likely(!ptrace_event_enabled(current, trace)))   trace = 0; }  p = copy_process(clone_flags, stack_start, stack_size,    child_tidptr, NULL, trace, tls, NUMA_NO_NODE); add_latent_entropy(); /*  * Do this prior waking up the new thread - the thread pointer  * might get invalid after that point, if the thread exits quickly.  */ if (!IS_ERR(p)) {  struct completion vfork;  struct pid *pid;   trace_sched_process_fork(current, p);   pid = get_task_pid(p, PIDTYPE_PID);  nr = pid_vnr(pid);   if (clone_flags & CLONE_PARENT_SETTID)   put_user(nr, parent_tidptr);   if (clone_flags & CLONE_VFORK) {   p->vfork_done = &vfork;   init_completion(&vfork);   get_task_struct(p);  }   wake_up_new_task(p);   /* forking complete and child started to run, tell ptracer */  if (unlikely(trace))   ptrace_event_pid(trace, pid);   if (clone_flags & CLONE_VFORK) {   if (!wait_for_vfork_done(p, &vfork))    ptrace_event_pid(PTRACE_EVENT_VFORK_DONE, pid);  }   put_pid(pid); } else {  nr = PTR_ERR(p); } return nr;}
 

转载地址:http://pzhti.baihongyu.com/

你可能感兴趣的文章
数组中累加和为定值K的最长子数组长度
查看>>
素数对--腾讯2017校招编程
查看>>
JAVA集合--ArrayList实现原理
查看>>
synchronized与Lock
查看>>
数据库索引
查看>>
实现包含min,max,push,pop函数的栈
查看>>
实验2-6 字符型数据的输入输出
查看>>
实验3-5 编程初步
查看>>
实验4-1 逻辑量的编码和关系操作符
查看>>
实验5-2 for循环结构
查看>>
实验5-3 break语句和continue语句
查看>>
实验5-4 循环的嵌套
查看>>
实验5-5 循环的合并
查看>>
实验5-6 do-while循环结构
查看>>
实验5-7 程序调试入门
查看>>
实验5-8 综合练习
查看>>
第2章实验补充C语言中如何计算补码
查看>>
深入入门正则表达式(java) - 命名捕获
查看>>
使用bash解析xml
查看>>
android系统提供的常用命令行工具
查看>>