I'm trying to write a very simple piece of code for a class, but I'm just stumped as to why I can't compile it. Sorry if this is a duplicate or silly question, but I couldn't find any others that answered this for me. My full program is pasted below. When I try to compile, I get the following error:
test.c: In function 'main':
test.c:7:27: error: expected ';' before '{' token
Here's the code:
#include<stdio.h>
#include<linux/sched.h>
#include<linux/kernel.h>
int main(){
struct task_struct *task;
for_each_process(task){
printf("I found task: %d\n", task->pid);
}
return 0;
}
I feel like I'm missing something painfully obvious, can anyone point out what the problem is here? I've tried initializing the 'task' object as NULL and using a simpler printf statement that just prints 'test', but nothing I've tried has fixed this compilation error.
The macro has been moved to <linux/sched/signal.h>
in this commit c3edc4010e9d102eb7b8f17d15c2ebc425fed63c in 2017. (https://github.com/torvalds/linux/commit/c3edc4010e9d102eb7b8f17d15c2ebc425fed63c).
(For someone who has trouble in compiling for this reason.)
The preprocessor token you are using for_each_process
is either not defined, or not defined to do what you think it does.
Every C++ compiler I've used can be told to dump the post-preprocessing output. If you pass the flag that makes this happen when building your source file, you'll see the code that the compiler is seeing and screwing up on.
gcc -E
clang -E
or the /E
flag in visual studio (heh) for example.
As @Ulrich has mentioned above, apparently that macro is only available within the kernel. Attempting to read <linux/sched.h>
directly and determine this is challenging, as there are many, many ifdef/endif pairs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With