关于 task_struct 结构????? 编译问题,求指点。

lixdrvor007 2013-07-18 10:00:27
#include <linux/sched.h>

int main()
{
struct task_struct *task;
for(task=current; task!=&init_task; task=task->parent)
;
printf("%d\n",task->pid);
}


task_init.c: In function 'main':
task_init.c:7:11: error: 'current' undeclared (first use in this function)
task_init.c:7:11: note: each undeclared identifier is reported only once for each function it appears in
task_init.c:7:27: error: 'init_task' undeclared (first use in this function)
task_init.c:7:47: error: dereferencing pointer to incomplete type
task_init.c:9:2: warning: incompatible implicit declaration of built-in function 'printf'
task_init.c:9:20: error: dereferencing pointer to incomplete type

上面的程序如何能编译,目的是获得到 第一个进程init的 pid。
...全文
209 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
aria 2013-07-19
  • 打赏
  • 举报
回复
你写的是用户态的C程序吧,task_struct是内核态的结构,不能直接用... 在头文件和其他一般会有宏控制。 你改成内核模块、驱动的方式来访问task列表吧,建议搜索下Linux驱动相关的基本知识先。
lixdrvor007 2013-07-19
  • 打赏
  • 举报
回复
to 2楼: 嗯,好像明白了些。
一根烂笔头 2013-07-18
  • 打赏
  • 举报
回复
查看下头文件源文件,到底有没有这个结构体

4,441

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧