I am trying to do the following - Writing a kernel module that lists all current tasks in a Linux system beginning from the init task. Output the task name (known as executable name), state and process id of each task in a tree structure.
The Error I am getting is this : (when I run the C program named "p1.c") Compile error: linux/init.h: No such file or directory
The p1.c
program is:
#include <init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched/task.h>
/*OS Project_Final*/
void dfs(struct task_struct *task, int indent)
{
struct task_struct *task_next;
struct list_head *list;
indent += 5;
list_for_each(list, &task->children);
task_next = list_entry(list, struct task_struct, sibling);
printk("%*s pid: %d pname: %s state :%d#n", indent, "", task_next->pid, task_next->comm, task_next->state);
dfs(task_next, indent);
}
int dfs_init(void)
{
printk("Loading module\n");
printk("pid: %d pname: %s state: %d\n", init_task.pid, init_task.comm, init_task.state);
dfs(&init-task, 0);
printk("Module Loaded\n");
return 0;
}
void dfs_exit(void)
{
printk("Module removed\n");
}
module_init(dfs_init);
module_exit(dfs_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Simple Module");
MODULE_AUTHOR("XXXXXX");
I am getting the error when I ran the command:
gcc -c p1.c
and the MakeFile
is placed in the directory named header
(The header
is located in the same directory as the p1.c
C file)
Makefile is as below:
obj-m += p1.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
How to resolve this error?
I tried running the following commands -
sudo apt install linux-headers-generic
& sudo apt install make
. But despite this, I am getting the same error.