如何在Linux内核空间中读取环形缓冲区? [英] How to read ring buffer within linux kernel space?

查看:322
本文介绍了如何在Linux内核空间中读取环形缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Linux字符驱动程序,该驱动程序可以在用户空间中打印系统日志.就像命令"dmesg"一样. 我了解到,我们使用"printk"打印的所有日志都将发送到名为环形缓冲区"的空间.所以我有个问题:

I'm writing a Linux character driver which can print system logs in user space. Just as the command 'dmesg' does. I've learned that all the log that we print with 'printk' will be sent to a space named ring buffer. So I have the questions:

  1. 环形缓冲区是否在内核空间内?
  2. 如果是这样,我如何读取内核空间中的环形缓冲区? (我尝试阅读dmesg.c的源代码.但这没有帮助.)

推荐答案

您正在寻找的是/proc/kmsg.这是内核环形缓冲区!

What you are looking for is /proc/kmsg. This is the kernel ring buffer!

  1. 是的,这在内核空间内.任何尝试读取它的进程都应该具有读取它的超级用户权限!

  1. Yes, this is inside kernel space. Any process trying to read it should have super user privileges to read it!

如何读取环形缓冲区?这是来自IBM Developerworks的精美插图

How to read it the ring buffer? Here is a beautiful illustration from IBM Developerworks

dmesg将是您的第一选择! dmesg 如何完成任务?通过调用syslog() syslog 是如何工作的?通过系统调用界面,该界面依次调用do_syslog(). do_syslog()整理操作是否像.

dmesg would be your first resort! How does dmesg accomplish its task? By a call to syslog()! How does syslog do its job? Through the system call interface which in turn call do_syslog(). do_syslog() does the finishing act like this.

还有更多资源可为您提供有关/proc/kmsg和常规内核记录的更多信息-

Here are a few more resources to get you more info about /proc/kmsg and kernel logging in general-

  1. http://www.makelinux.net/ldd3/chp -4-sect-2

http://www .ibm.com/developerworks/linux/library/l-kernel-logging-apis/index.html

http://oguzhanozmen .blogspot.in/2008/09/kernel-log-buffering-printk-syslog-ng.html

这篇关于如何在Linux内核空间中读取环形缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆