关于写个内核模块打印进程链表的一些信息的程序

本文介绍如何编写一个内核模块,用于在Linux系统中打印进程链表的相关信息。在插入模块并查看日志时,由于默认的`tail`命令只会显示最后十行,因此需要使用`tail -n 200 /var/log/messages`来查看全部进程号和名称。通过这种方式,可以确保所有进程信息都被完整显示。
摘要由CSDN通过智能技术生成
/*************************************************
* 函数名:TaskTest.c
* 功能  :尝试写下linux书上遍历进程的程序
* 时间  :2015/10/14
*
*****************************************/

#include <linux/module.h> //任何模块编程都要包含这个头文件
#include <linux/kernel.h> //包含了常用的内核函数
#include <linux/init.h>	//包含了宏 __init和__exit
#include <linux/list.h> //包含了内核中链表的相关函数
#include <linux/sched.h> //包含了关于进程PCB链表的相关内容


//初始化函数  print_pid()
static int __init print_pid(void){
	struct task_struct *task, *p;
	struct list_head *pos;
	int count = 0;

	printk("Hello World enter begin:\n");

	task = &init_task;

	list_for_each(pos, &task->tasks){
		p = list_entry(pos, struct task_struct, tasks);
		count++;
		printk("%d--->%s\n", p->pid, p->comm);
	}

	printk("the number of process is:%d\n", count);
	
	return 0;
}

//退出和清理函数  lkp_cleanup()
static void __exit lkp_cleanup(void){

	printk("<1&g
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值