向 Linux 控制台回显值
在 C 语言中,如何将系统调用中的值输出到 Linux 控制台,以便在 dmesg 后该值可见?我使用什么方法进行打印?
How can I, in C, output a value from a syscall to the Linux console so that it will be visible after a dmesg
? What method do I use for printing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在寻找
printk()
函数;有关其支持的类型的一些文档可以在Documentation/printk-formats.txt
中找到。它在kernel/printk.c
中定义。You're looking for the
printk()
function; some documentation on the types that it supports is found inDocumentation/printk-formats.txt
. It is defined inkernel/printk.c
.我假设你的意思是在用户空间中。您可以将该字符串写入
/dev/kmsg
。在 shell 中,只需echo
即可。在C中,这也很容易。但如果你指的是在内核空间,当然,你需要调用
printk()
。I assume you mean in the user-space. You can write the string to
/dev/kmsg
. In shell, justecho
it. In C, it would be also very easy.But if you mean in kernel space, of course, you need to call
printk()
.此外,您可能会感兴趣(即使这并不能完全回答您的问题),通过 openlog & ; syslog 功能。在应用程序内部,它们是获取系统日志记录的正确方法。
In addition, you might be interested (even if that does not answer exactly your question), by the openlog & syslog functions. From within an application, they are the proper way to get system logging.