find_get_pid 解析

http://blog.sina.com.cn/s/blog_821c73630100x1sr.html


注解:find_get_pid <wbr>解析
       1> 位置 :/linux/kernel/pid.c
       2> 声明 :struct pid * find_get_pid(int ns);
       3> 功能 :此函数根据提供的进程号获取对应的进程描述符,并且将该进程描述符中的字段count加1.即此进
                       程的用户数目加1;
       4>输入参数:表示进程的进程号
       5>输出参数:进程的描述符,该类型在__task_pid_nr_ns()博客有提到。
代码:find_get_pid <wbr>解析

#include<linux/module.h>
#include<linux/pid.h>
#include<linux/sched.h>
MODULE_LICENSE("GPL");
static int __init find_get_pid_init(void);
static void __exit find_get_pid_exit(void);

int my_function(void *arg)
{
    printk("<0> in the kernel thread function !\n");
    return 0;
}

int __init find_get_pid_init(void)
{
    int result;
    struct pid * kpid;

    printk("<0> into find_get_pid init.\n");
    result = kernel_thread(my_function,NULL, CLONE_KERNEL);
    kpid = find_get_pid(result);
    printk("<0>the count of the pid is : %d\n", (int)(kpid->count.counter));
    printk("<0>the level of the pid is : %d\n", kpid->level );

    printk("<0>the pid of the find_get_pid is : %d\n",kpid->numbers[kpid->level].nr);
    printk("<0>the result of the kernel_thread is : %d\n",result);
    printk("<0>out find_get_pid_init.\n");
    return 0;
}
void __exit find_get_pid_exit(void)
{
    printk("<0> Goodbye find_getpid");
}
module_init(find_get_pid_init);
module_exit(find_get_pid_exit);

结果:find_get_pid <wbr>解析
find_get_pid <wbr>解析
提示:在新进程创建之初,进程描述符字段count的值为1,而函数find_get_pid()执行后,进程描述符字段count变为2
调用关系;

                                                   find_get_pid(int ns)
                                                              |
                                                              |
                                                   find_vpid(int ns)
                                                              |
                                                              |
                                  find_pid_ns(int nr, struct pid_namespace*)
                                                              |
                                                              |
                                                      get_pid()
                                                              |
                                                              |
                                                      atomic_inc()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值