#include <linux/module.h>
#include <linux/sched.h>
//#include <linux/kernel.h>
#define TASK_ZOMBIE 4
int init_module(void)
{
struct task_struct *task;
int num_running, num_int, num_unint, num_zombie, num_stopped, num_process;
num_process = num_running = num_int = num_unint = num_zombie = num_stopped = 0;
printk("<1>Hello, this module prints informations of current processes.\n");
for_each_process(task){
printk("%d\nProcess Name: %s\n", num_process, task->comm);
printk("Process Pid: %d\n", task->pid);
printk("Process State: ");
num_process++;
if(task->exit_state & TASK_STOPPED){
printk("TASK_STOPPED ");
num_stopped++;
continue;
}
if(task->exit_state & TASK_ZOMBIE){
printk("TASK_ZOMBIE ");
num_zombie++;
continue;
}
if(task->state & TASK_RUNNING){
printk("TASK_RUNNING ");
num_running++;
}
if(task->state & TASK_INTERRUPTIBLE){
printk("TASK_INTERRUPTIBLE ");
num_int++;
}
if(task->state & TASK_UNINTERRUPTIBLE){
printk("TASK_UNINTERRUPTIBLE ");
num_unint++;
}
printk("\nProcess State: %ld\n", task->state);
printk("Process Parent: %s\n\n", task->parent->comm);
}
printk("---------------Statistics----------------\n");
printk("Process Running: %d\n", num_running);
printk("Process Interruptible: %d\n", num_int);
printk("Process Uninterruptible: %d\n", num_unint);
printk("Process Zombie: %d\n", num_zombie);
printk("Process Stopped: %d\n", num_stopped);
printk("Total Processes: %d\n", num_process);
return 0;
}
void cleanup_module(void){
printk("Removing module print_process_info...\n");
printk("Succeeded!\n");
printk("<1> Goodbye!\n");
}
MODULE_LICENSE("GPL");
内核1
最新推荐文章于 2022-10-19 19:32:39 发布