zoukankan      html  css  js  c++  java
  • Linux进程管理(三、 线程)

    // ---- refer glibc, pthread_create.c ----//
    
    int
    __pthread_create_2_0 (newthread, attr, start_routine, arg)
         pthread_t *newthread;
         const pthread_attr_t *attr;
         void *(*start_routine) (void *);
         void *arg;
    {
      ...
    
      return __pthread_create_2_1 (newthread, attr, start_routine, arg);
    }
    compat_symbol (libpthread, __pthread_create_2_0, pthread_create,
    	       GLIBC_2_0);
    

    下面宏定义说明pthread_create实现是在__pthread_create_2_0
    调用链:


    | glibc:: __pthread_create_2_0 --> __pthread_create_2_1 --> create_thread --> do_clone |
    - system call ->
    | kernel: sys_clone --> do_fork |


    进入内核后与创建进程一样调用do_fork, 唯一不同的是传入的参数不同:
    其中clone_flags = (CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGNAL
    | CLONE_SETTLS | CLONE_PARENT_SETTID
    | CLONE_CHILD_CLEARTID | CLONE_SYSVSEM
    | 0);

    而fork是的flags为SIGCHLD
    这里面CLONE_XXX 的意思其实是共享资源, 而不是再复制一份。
    所以, 在linux中线程在内核角度来说没有特殊的结构, 只是共享父进程某些资源的进程, 他们有自己的task_struct。

  • 相关阅读:
    A
    hdu 2108 Shape of HDU(判定是不是凸多边形)
    F
    J
    扩展欧几里得
    G
    A
    D
    E
    H
  • 原文地址:https://www.cnblogs.com/hushpa/p/5685658.html
Copyright © 2011-2022 走看看