Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6334

kernel module compilation error of macro for_each_process

$
0
0

I am trying to compile a program to list tasks linearly, such that if you run the command ps -el should have the same or similar output. my textbook says:"In the Linux kernel, the for_each_process() macro easily allows iteration over all current tasks in the system:

#include <linux/sched.h>struct task_struct *task;for_each_process(task) {   /* on each iteration task points to the next task */}

so I have the following:

#include <linux/init.h>#include <linux/kernel.h>#include <linux/module.h>#include <linux/sched.h>int tasks_lister_linear_init(void){  printk(KERN_INFO "Loading module...\n");  struct task_struct *task;  for_each_process(task)  {    printk(KERN_INFO "pid: %d | pname: %s | state: %ld\n", task->pid, task- >comm, task->state);  }  printk(KERN_INFO "Module loaded.\n");  return 0;}void tasks_lister_linear_exit(void){  printk(KERN_INFO "Module removed.\n");}module_init(tasks_lister_linear_init);module_exit(tasks_lister_linear_exit);

and when I go to make, I get an error saying

implicit declaration of function ‘for_each_process’; did you mean ‘for_each_node’?expected ‘;’ before ‘{’ token      |     for_each_process(task) {      |                                                     ^~      |                                                      ;

did I mean for_each_node rather than for_each_process as well as it is expecting a ; after for_each_process,

yet every call to this I have seen has not had a semicolon following. any advice on these errors would be greatly appreciated


Viewing all articles
Browse latest Browse all 6334

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>