把核心中的資訊列印到檔案

2021-05-26 04:41:40 字數 1601 閱讀 7901

1.  

#include 

#include 

#include 

#include 

#include 

#include 

#include 

#include 

#include 

#define my_file "/root/logfile"

char buf[128];

struct file *file = null;

static int __init init(void)

sprintf(buf,"%s", "the messages.");

old_fs = get_fs();

set_fs(kernel_ds);

file->f_op->write(file, (char *)buf, sizeof(buf), &file->f_pos);

set_fs(old_fs);

return 0;

}static void __exit fini(void)

module_init(init);

module_exit(fini);

module_license("gpl");

2. #include 

#include 

#include 

#include 

#include 

module_license("gpl");

module_author("mq110");

static void print_string(char *str)

}static int __init print_string_init(void)

static void __exit print_string_exit(void)

module_init(print_string_init);

module_exit(print_string_exit);

[/code]

我一般用putty登陸 編寫kernel module. printk資訊都存在/var/log/message裡了.~

用這個程式就能顯示在螢幕上了.你可以把print_string 符號匯出來.

3. 

修改一下/etc/syslog.conf 檔案

#kern.*       /dev/console

你列印的東西可能是某個級別的資訊。比如說debug,這用printk 可以控制 。

那麼就寫程

kern.debug /var/log/kern_debug.log

-------------------------

printk(kern_alert "hello, world/n"); 

對應 /etc/syslog.conf 中的

kern.alert                      /kernel.txt

實驗成功,修改後要執行

server syslogd restart 重啟日誌服務。

此方法等於用日誌服務幫你做這個事情。該資訊用

dmesg 命令也可以看到。

printk資訊列印到指定檔案 終端 網路

有的時候除錯核心程式,經常要將資訊列印到其他地方如指定檔案或終端還有網路,網路的話dreanice版主寫過個netconsole我這裡就不說了.列印到檔案 include include include include include include include include include ...

把log4j的日誌資訊列印到swing元件上

網上有很多把system的資訊列印到swing的元件上的,這個就不說了。但是預設情況下log4j的是列印不到的。那怎麼辦呢,肯定首先要做到還是讓system的資訊列印到swing,接著再來操作這個步驟 為自己應用程式的輸出控制台還是不錯的。有個問題,如果要捕獲 log4j 的輸出必須選擇 1.2.1...

《驅動除錯 除錯資訊列印到proc虛擬檔案》

printk 會將列印資訊存在核心的環形緩衝區log buf裡,可以通過dmesg命令來檢視log buf 1.環形緩衝區log buf又是存在核心的哪個檔案呢?位於 proc kmsg裡,所以除了dmesg命令檢視,也可以使用cat proc kmsg來檢視。2.但是,dmesg命令和cat pr...