久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

printk函數(shù)的幾個消息記錄等級

 cana_xzy 2010-05-18
printk函數(shù)
        We used the printk function in earlier chapters with the simplifying assumption that it works like printf. Now it's time to introduce some of the differences.
        我們在前面章節(jié)中簡單地把printk當(dāng)作printf函數(shù)來使用。現(xiàn)在是時候來介紹它的一些不同之處了,。
        One of the differences is that printk lets you classify messages according to their severity by associating different loglevels, or priorities, with the messages. You usually indicate the loglevel with a macro. For example, KERN_INFO, which we saw prepended to some of the earlier print statements, is one of the possible loglevels of the message. The loglevel macro expands to a string, which is concatenated to the message text at compile time; that's why there is no comma between the priority and the format string in the following examples. Here are two examples of printk commands, a debug message and a critical message:
        其中一個不同點是,,printk允許你按照相關(guān)的記錄級或優(yōu)先級將消息嚴(yán)格分類,。通常你需要一個宏來指定記錄等級。例如,,KERN_INFO,我們在早先的的例子中看到過這個宏,,它就是消息記錄等級的一種。記錄等級宏的作用是擴展為一個字符串,,這個字符串會在編譯期間與相應(yīng)的消息文本相連接,;這就解釋了下面例子中為什么在優(yōu)先級和格式化字符串之間沒有逗號了。下面是兩個printk函數(shù)的例子,,一個是調(diào)試消息,,一個是臨界消息:

printk(KERN_DEBUG "Here I am: %s:%i\n", _ _FILE_ _, _ _LINE_ _);
 
 

printk(KERN_CRIT "I'm trashed; giving up on %p\n", ptr);
 
 
        There are eight possible loglevel strings, defined in the header   ; we list them in order of decreasing severity:
       
        在頭文件<linux/kernel.h>中共定義了八個可用的記錄級;我們下面按其嚴(yán)重性倒序列出:
KERN_EMERG
Used for emergency messages, usually those that precede a crash.
用于突發(fā)性事件的消息,,通常在系統(tǒng)崩潰之前報告此類消息,。
KERN_ALERT
A situation requiring immediate action.
在需要立即操作的情況下使用此消息。
KERN_CRIT
Critical conditions, often related to serious hardware or software failures.
用于臨界條件下,,通常遇到嚴(yán)重的硬軟件錯誤時使用此消息,。
KERN_ERR
Used to report error conditions; device drivers often use KERN_ERR to report hardware difficulties.
用于報告錯誤條件;設(shè)備驅(qū)動經(jīng)常使用KERN_ERR報告硬件難題,。
KERN_WARNING
Warnings about problematic situations that do not, in themselves, create serious problems with the system.
是關(guān)于問題狀況的警告,,一般這些狀況不會引起系統(tǒng)的嚴(yán)重問題。
KERN_NOTICE
Situations that are normal, but still worthy of note. A number of security-related conditions are reported at this level.
該級別較為普通,,但仍然值得注意,。許多與安全性相關(guān)的情況會在這個級別被報告。
KERN_INFO
Informational messages. Many drivers print information about the hardware they find at startup time at this level.
信息消息,。許多驅(qū)動程序在啟動時刻用它來輸出獲得的硬件信息,。
KERN_DEBUG
Used for debugging messages.
用于輸出調(diào)試信息
        Each string (in the macro expansion) represents an integer in angle brackets. Integers range from 0 to 7, with smaller values representing higher priorities.
        每一個字符串(由宏擴展而成)表示了尖括號內(nèi)的一個整數(shù)。數(shù)值范圍從0到7,,數(shù)值越小,,優(yōu)先級越高。
        A printk statement with no specified priority defaults to DEFAULT_MESSAGE_LOGLEVEL, specified in kernel/printk.c as an integer. In the 2.6.10 kernel, DEFAULT_MESSAGE_LOGLEVEL is KERN_WARNING, but that has been known to change in the past.
         一個printk的缺省優(yōu)先級是DEFAULT_MESSAGE_LOGLEVEL,它是一個在kernel/printk.c文件中指定的整數(shù),。在 2.6.10內(nèi)核中,,DEFAULT_MESSAGE_LOGLEVEL相當(dāng)于KERN_WARNING,但據(jù)說在早期版本中這是兩個不同的優(yōu)先級。
        Based on the loglevel, the kernel may print the message to the current console, be it a text-mode terminal, a serial port, or a parallel printer. If the priority is less than the integer variable console_loglevel, the message is delivered to the console one line at a time (nothing is sent unless a trailing newline is provided). If both klogd and syslogd are running on the system, kernel messages are appended to /var/log/messages (or otherwise treated depending on your syslogd configuration), independent of console_loglevel. If klogd is not running, the message won't reach user space unless you read /proc/kmsg (which is often most easily done with the dmesg command). When using klogd, you should remember that it doesn't save consecutive identical lines; it only saves the first such line and, at a later time, the number of repetitions it received.
        基于這些記錄級,,內(nèi)核可以把消息輸出到當(dāng)前的控制臺,,也可以是一個文本模式的終端,一個串口,,或是一個并口打印機,。如果優(yōu)先級小于整形變量 console_loglevel,那么一次將會只發(fā)送一行消息到控制臺中(除非遇到一個換行符,,否則將什么都不會發(fā)送),。如果系統(tǒng)中運行了klogd和syslogd進(jìn)程,那么內(nèi)核消息就會被完整地添加到/var/log/messages文件中(或者根據(jù)你的syslogd進(jìn)程的配置狀況進(jìn)行發(fā)送)而忽略console_loglevel,,如果klogd沒有運行,,那么消息將不會到達(dá)用戶空間,除非你對/proc/kmsg文件讀?。▽嶋H上這項工作已被較早的dmesg命令完成),。當(dāng)使用klogd時,你應(yīng)該記住它不會保留重復(fù)的消息行,;對于它接收到的重復(fù)消息,它只會保留第一條,。
        The variable console_loglevel is initialized to DEFAULT_CONSOLE_LOGLEVEL and can be modified through the sys_syslog system call. One way to change it is by specifying the -c switch when invoking klogd, as specified in the klogd manpage. Note that to change the current value, you must first kill klogd and then restart it with the -c option. Alternatively, you can write a program to change the console loglevel. You'll find a version of such a program in misc-progs/setlevel.c in the source files provided on O'Reilly's FTP site. The new level is specified as an integer value between 1 and 8, inclusive. If it is set to 1, only messages of level 0 (KERN_EMERG) reach the console; if it is set to 8, all messages, including debugging ones, are displayed.
        被初始化為DEFAULT_CONSOLE_LOGLEVEL的console_loglevel變量可以通過sys_syslog系統(tǒng)調(diào)用修改,。改變它內(nèi)容的一個方法就是在調(diào)用klogd時使用-c選項,具體參考klogd的man幫助,。請注意,,為了改變當(dāng)前的數(shù)值,你必須首先結(jié)束klogd進(jìn)程,,并且用-c選項重新啟動它,。另一種方法是,你可以寫一個應(yīng)用程序來改變控制臺的記錄等級,。你可以在O'Reilly的FTP站點提供的源代碼文件中找到/misc-progs/setlevel.c文件,,其中就有一個這樣的程序。新記錄級為一個1到8的整數(shù),。如果設(shè)置為1,,那么只有優(yōu)先級為0(KERN_EMERG)的消息才可以到達(dá)控制臺;如果等級設(shè)置為8,,那么包括調(diào)試信息在內(nèi)的所有消息都會被顯示,。
        It is also possible to read and modify the console loglevel using the text file /proc/sys/kernel/printk. The file hosts four integer values: the current loglevel, the default level for messages that lack an explicit loglevel, the minimum allowed loglevel, and the boot-time default loglevel. Writing a single value to this file changes the current loglevel to that value; thus, for example, you can cause all kernel messages to appear at the console by simply entering:
        也可以通過文本文件/proc/sys/kernel/printk來獲取和更改控制臺的記錄等級。這個文件中存儲著四個整型數(shù)值:當(dāng)前記錄級,,缺省記錄級,,最低記錄級和啟動時刻的缺省記錄級。可以向該文件寫入一個單一數(shù)值來改變當(dāng)前記錄級,;例如,,如果你可以想所有的內(nèi)核消息都可以在控制臺中顯示,可以使用以下命令:
# echo 8 > /proc/sys/kernel/printk
        It should now be apparent why the hello.c sample had the KERN_ALERT; markers; they are there to make sure that the messages appear on the console.
        現(xiàn)在你應(yīng)該明白在hello.c示例代碼中為什么會有KERN_ALERT;標(biāo)識了吧,;這樣做可以保證消息順利地輸出到控制臺中
文章出處:飛諾網(wǎng)(www.):http://dev./course/6_system/linux/Linuxjs/2008717/133389.html

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點,。請注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多