#函数
__task_pid_nr_ns(struct task_struct *task,enum pid_type type,struct pid_namespace *ns) #文件包含 #include<linux/sched.h> #函数定义 ##在内核源代码的位置 linux-3.2.64/kernel/pid.c ##函数定义格式:
#函数功能描述 此函数用于获取进程的进程号,但应该满足以下几个条件。 1.参数type如果不等于PIDTYPE_PID,则参数task用其所属任务组的第一个任务赋值,否则保持task不变。
2.此进程是参数task任务描述符的进程。
3.保证进程描述符和pid_namespaces和参数ns相同。
#参数补充(未写)
#举例
结合以前的知识,写出Makefile,执行
make
然后,键入
insmod __task_pid_nr_ns.ko
这时一般终端就会有消息产出,如果没有可以接着使用 __dmesg -c__命令 ##终端信息
Message from syslogd@debian at Nov 21 15:28:12 ... kernel:[ 458.244921] into __task_pid_nr_ns_init. Message from syslogd@debian at Nov 21 15:28:12 ... kernel:[ 458.244971] the pid of the find_get_pid is :2915 Message from syslogd@debian at Nov 21 15:28:12 ... kernel:[ 458.244980] the result of __task_pid_nr_ns is :2915 Message from syslogd@debian at Nov 21 15:28:12 ... kernel:[ 458.244988] the result of kernel_thread is :2915 Message from syslogd@debian at Nov 21 15:28:12 ... kernel:[ 458.244995] the pid of current thread is :2914 Message from syslogd@debian at Nov 21 15:28:12 ... kernel:[ 458.245002] out __task_pid_nr_ns_init. Message from syslogd@debian at Nov 21 15:28:12 ... kernel:[ 458.245964] in the kernel thread function dmesg -c dmesg: klogctl failed: 不允许的操作 yubo@debian:~/linux/process$
#find_get_pid() 定义:struct pid *find_get_pid(int nr) ##功能 此函数根据提供的进程号获取对应的进程描述符,并使进程描述符的count的值加1即此进程的用户数加1
##参数说明 nr即为进程号 ##返回参数 返回与参数提供的进程号对应的进程描述符,进程描述符定义如下:
##find_get_pid()应用举例
##输出结果
Message from syslogd@debian at Nov 23 05:42:16 ... kernel:[ 3162.689851] into the find_get_pid_init. Message from syslogd@debian at Nov 23 05:42:16 ... kernel:[ 3162.689863] the count of the pid is :2 Message from syslogd@debian at Nov 23 05:42:16 ... kernel:[ 3162.689864] the level of the pid is :0 Message from syslogd@debian at Nov 23 05:42:16 ... kernel:[ 3162.689866] the pid of the find_get_pid is :3554 Message from syslogd@debian at Nov 23 05:42:16 ... kernel:[ 3162.689867] the result of the kernel_thread is :3554 Message from syslogd@debian at Nov 23 05:42:16 ... kernel:[ 3162.689868] out find_get_pid_init. Message from syslogd@debian at Nov 23 05:42:16 ... kernel:[ 3162.690635] in the kerenl thread function!