向 Linux 控制台回显值

发布于 2024-12-17 11:35:32 字数 67 浏览 2 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

停顿的约定 2024-12-24 11:35:32

您正在寻找 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 in Documentation/printk-formats.txt. It is defined in kernel/printk.c.

別甾虛僞 2024-12-24 11:35:32

我假设你的意思是在用户空间中。您可以将该字符串写入/dev/kmsg。在 shell 中,只需 echo 即可。在C中,这也很容易。

[root@cr0 ~]# echo hello > /dev/kmsg
[root@cr0 ~]# dmesg | tail -1
[24156.408735] hello

但如果你指的是在内核空间,当然,你需要调用printk()

I assume you mean in the user-space. You can write the string to /dev/kmsg. In shell, just echo it. In C, it would be also very easy.

[root@cr0 ~]# echo hello > /dev/kmsg
[root@cr0 ~]# dmesg | tail -1
[24156.408735] hello

But if you mean in kernel space, of course, you need to call printk().

半仙 2024-12-24 11:35:32

此外,您可能会感兴趣(即使这并不能完全回答您的问题),通过 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文