#include <linux/sched.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
struct task_struct *task;
task = current;
printf("Proc PID is %ld\n",(long)task->pid);
exit(EXIT_SUCCESS);
}
当我尝试编译时出现以下错误:
*current.c: In function ‘main’:
current.c:9:9: error: ‘current’ undeclared (first use in this function)
current.c:9:9: note: each undeclared identifier is reported only once for each function it appears in
current.c:10:40: error: dereferencing pointer to incomplete type*
我使用的是 Linux 内核 3.2.0.4-amd64。 我哪里错了?
最佳答案
您是否尝试在用户空间编程中使用 Linux Kernel 的数据结构、变量?如果是这样,你就错了。 task_struct 是 Linux 内核的内部数据结构。 current 也是 Linux 内核内部寄存器变量。用户空间程序不能使用它们。
关于linux - 尝试使用 "current"宏时出现编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16247516/