35 lines
983 B
Markdown
35 lines
983 B
Markdown
|
# Linux Kernel 打印输出
|
|||
|
|
|||
|
## printk
|
|||
|
|
|||
|
**函数原型:**
|
|||
|
|
|||
|
```cpp
|
|||
|
int printk(const char *fmt, ...);
|
|||
|
```
|
|||
|
|
|||
|
**说明:**
|
|||
|
|
|||
|
内核打印输出函数,可通过 dmesg 查看其输出信息。printk 可设置打印级别,如下:
|
|||
|
|
|||
|
```cpp
|
|||
|
#define KERN_EMERG "<0>" /* system is unusable */
|
|||
|
#define KERN_ALERT "<1>" /* action must be taken immediately */
|
|||
|
#define KERN_CRIT "<2>" /* critical conditions */
|
|||
|
#define KERN_ERR "<3>" /* error conditions */
|
|||
|
#define KERN_WARNING "<4>" /* warning conditions */
|
|||
|
#define KERN_NOTICE "<5>" /* normal but significant condition */
|
|||
|
#define KERN_INFO "<6>" /* informational */
|
|||
|
#define KERN_DEBUG "<7>" /* debug-level messages */
|
|||
|
```
|
|||
|
|
|||
|
dmesg 可通过打印级别过滤消息。
|
|||
|
|
|||
|
**参数:**
|
|||
|
|
|||
|
fmt:格式化输出字符串。可使用 %d,%s,%c 等。
|
|||
|
|
|||
|
**返回值:**
|
|||
|
|
|||
|
实际输出的字符个数。
|