3

我正在尝试向 Linux 添加一些东西task_struct

在这个区域中,我从用户那里复制了一个字符串并尝试将它存储在我的结构中。

我尝试通过添加printk将打印复制的字符串来调试我的代码。

这是代码的调试部分:

newTODO->TODO_description=(char*)(kmalloc(in_description_size+1,0));
    if( newTODO->TODO_description){
        kfree(newTODO);
        return -1;
    }

    res=copy_from_user(newTODO->TODO_description, in_TODO_description, in_description_size);
        if (res)                                //  error copying from user space, 1 or more char werent copied.
        {
            printk(KERN_ALERT "function: create element failed to copy from user\n");
            return -EFAULT;
        }
    newTODO->TODO_description[in_description_size]='\o';
    printk(KERN_ALERT "the copied string is: %s \n",newTODO->TODO_description);

对我来说必须重要的印刷品是

printk(KERN_ALERT "the copied string is: %s \n",newTODO->TODO_description);

它会起作用吗?

了解 printk:

每当调用 printk 时,我什么时候从终端运行我的测试文件,它会将输出打印到工作终端?

4

1 回答 1

1

printk 函数将在内核消息缓冲区中附加消息,但除非您给出命令,否则此缓冲区的包含不会显示在终端上。

正如 Ilya Matveychikov 所说,您可以使用“dmesg”命令转储内核消息缓冲区。

或使用以下命令获取实时内核消息观察。

echo 8 > /proc/sys/kernel/printk
tail -f /var/log/kern.log &



cat /proc/kmsg & (Android 环境)

于 2015-12-14T06:17:11.363 回答