http://blog.sina.com.cn/s/blog_821c73630100x1sr.html
注解:
代码:
#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);
结果:
提示:在新进程创建之初,进程描述符字段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()