遇到一个问题,在一个内核模块里使用current->comm保存当前任务名,编译报错:dereferencing pointer to incomplete type。
经过搜索发现,除了要包含current.h外,还要包含sched.h。原因是struct task_struct在sched.h里定义。comm是数组字符串,长度是TASK_COMM_LEN,一般是16个字节,记得保证足够的空间,防止内存越界。
用法实例如下:
#include <linux/sched.h>
#include <asm/current.h>
static char g_cfg_app_name[TASK_COMM_LEN*2] = { 0 };
strncpy(g_cfg_app_name,current->comm,TASK_COMM_LEN);
参考文章
http://www.xuebuyuan.com/1814455.html

本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。