进程fork处理

进程或者线程创建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; }

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值