/dev/kmsg在串列埠列印除錯資訊
阿新 • • 發佈:2019-01-02
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
static void mp4api_dbprint_ttxgz(char* format,...)
{
va_list args;
int fd;
char string[1000];
va_start(args,format);
vsprintf(string,format,args);
va_end(args);
fd = open("/dev/kmsg" ,O_RDWR);
if(fd == -1)
{
return;
}
write(fd,string,strlen(string)+1);
close(fd);
}
要注意的是,linux起來以後,需要在終端修改/dev/kmsg的許可權為777
這樣做的好處是,開發的時候當kernel連不上adb的時候,沒辦法通過ddms看Logcat列印,在終端看logcat列印又太麻煩,就可以用這種方式直接在串列埠新增列印。
但是這裡的write可能是阻塞式,有可能讓程式變慢。